Doom3world

The world is yours! Doom 3 - Quake 4 - ET:QW - Prey - Rage
It is currently Sat May 18, 2013 9:23 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Realistic Weapon Recoil with Scripts[Help Needed]
PostPosted: Wed Jun 06, 2012 5:59 pm 
Offline
The first 10 posts have been the best...

Joined: Wed Jun 06, 2012 5:56 pm
Posts: 22
Hey everyone. I apologize if i have posted in the wrong forum/subforum, i am new here as you can see. Now, i am a novice modder-nothing serious. However, i want to make the spread of weapons increase with every shot fired. Is that possible?

Please take into account that i am a complete newbie when it comes to scripting.
Could anyone tell me how this could be done, presented with examples? I would really appreciate the help.
Thanks for reading this, and thanks even more if you actually help me do this :D

EDIT: Guys, I think i've figured at least one half of this out. Now my pistol's recoil gets worse when im firing, now i only need to make it stop when im not firing :P
Code:
if ( spread < 10 ) {
                spread = spread + 1;
        }



I just had to put this code right after playAnim in the Fire state.
Now my idea for making the spread lower when you don't fire is... While the weapon is in the IDLE state, wait 0.3 seconds and lower spread by 1. If spread is 1, make spread 1 again and again. I think this should work :lol:

EDIT2: It did work 8)


Top
 Profile E-mail  
 
 Post subject: Re: Realistic Weapon Recoil with Scripts[Help Needed]
PostPosted: Wed Jul 11, 2012 3:08 pm 
Offline
is connecting to Doom3world.org

Joined: Wed Jul 11, 2012 2:51 am
Posts: 9
Cool. Can you post the second part of the code? Thanks.


Top
 Profile E-mail  
 
 Post subject: Re: Realistic Weapon Recoil with Scripts[Help Needed]
PostPosted: Wed Jul 11, 2012 8:28 pm 
Offline
is sad because his cool title went away
User avatar

Joined: Tue Aug 12, 2003 11:38 am
Posts: 699
Location: Underneath it all, waiting to get to the surface.
while spread is bigger than 1 substract 1 frome spread... no need to keep checking it.

_________________
-->7318<--


Top
 Profile  
 
 Post subject: Re: Realistic Weapon Recoil with Scripts[Help Needed]
PostPosted: Wed Jul 11, 2012 11:57 pm 
Offline
is connecting to Doom3world.org

Joined: Wed Jul 11, 2012 2:51 am
Posts: 9
If it doesn't keep checking, then how else is the interval for spread reduction defined? You don't necessarily want the spread to reset back to 0 instantaneously. What's more you'd probably want to ensure that the interval at which spread is reduced is at least slightly slower than the weapon's fire rate. Otherwise the spread could start resetting before the next shot is fired. The rate of reduction could potentially need to be pretty specific.

That's why I'm curious to see a working syntax for this (besides the fact that I'm a code n00b).

EDIT: Nevermind, I found his code here: viewtopic.php?t=25578


Top
 Profile E-mail  
 
 Post subject: Re: Realistic Weapon Recoil with Scripts[Help Needed]
PostPosted: Thu Jul 12, 2012 10:49 am 
Offline
is sad because his cool title went away
User avatar

Joined: Tue Aug 12, 2003 11:38 am
Posts: 699
Location: Underneath it all, waiting to get to the surface.
because it only checks it and those the operations if the situation makes the conditional in the "while" true, once the situation makes the condition of the while fail it doesn't keep working on it. so it's it deactivates the operations inside the while instantly

while ( spread >= 2 ){
spread = spread - 1
}

(in every frame in the idle, reload or other situations where the pistol it's not shooting)

if spread it's way to quickly to get to the value you want, you could use an intermediate value instead of spread.

and once you shoot get a spread value based on how much this intermediate value is.

while ( z >= 1 ){
z = z - 1
}

like, every time you shoot: z = z + 100

and before you shoot you could check:

if (z == 0) {
spread = 1
}else if (z >= 10 && z < 20) {
spread = 2
}else if (z >= 20 && z < 30) {
spread = 3
}else{
spread = 4
}

or some kind of mathematical algorithm where you get spread out of z way more quickly without conditionals.

----------------------------------------

you could do a clever use of different chekings throught the animation system, and keep defining a float variable that once you get to shooting changes the spread, or you could use a thread just to check this.

But I think the "thread" way is a bad idea because way too many threads for doom 3 gets you to bad perform in the engine

_________________
-->7318<--


Top
 Profile  
 
 Post subject: Re: Realistic Weapon Recoil with Scripts[Help Needed]
PostPosted: Thu Jul 12, 2012 3:07 pm 
Offline
is connecting to Doom3world.org

Joined: Wed Jul 11, 2012 2:51 am
Posts: 9
Ok, so I followed MadHacker's code last night and got it to work without a hitch. So I'm guessing the interval at which the idle state runs the -1 process is every frame then? So is that 60 times per second, or 30 times per second?

Either way it explains why you need a pretty low value to create a visibly gradual reduction in spread.

Thanks for the help.


Top
 Profile E-mail  
 
 Post subject: Re: Realistic Weapon Recoil with Scripts[Help Needed]
PostPosted: Thu Jul 12, 2012 6:15 pm 
Offline
picked up 200 ammo

Joined: Tue Aug 31, 2004 7:31 pm
Posts: 279
Location: Ireland
You could use gametime instead of framerate to regulate the spread decrease, which would give you more control.

Here's one way, using pistol.script as example.

First, ad a new float 'firetime' to the weapon object:
Code:
object weapon_pistol : weapon_base {
   float      next_attack;
   float      spread;
   float      firetime;   // <= add this line

In weapon_pistol::Fire(), add these lines after the playAnim:
Code:
    playAnim( ANIMCHANNEL_ALL, "fire" );
    firetime = sys.getTime() + 2.0;   // add these lines and change 2 to the desired initial delay time
    if ( spread < 8 ) {                    //
            spread = spread + 1         //
    }                                          //


continued next post...

_________________
"Leave me alone, I know what I'm doing..." Kimi Raikkonen


Top
 Profile  
 
 Post subject: Re: Realistic Weapon Recoil with Scripts[Help Needed]
PostPosted: Thu Jul 12, 2012 6:16 pm 
Offline
picked up 200 ammo

Joined: Tue Aug 31, 2004 7:31 pm
Posts: 279
Location: Ireland
...and finally in weapon_pistol::Idle(), add these lines at the end of the while(1) loop, just before waitFrame();
Code:
           if ( firetime <= sys.getTime() && spread > 1 ) {
               spread = spread - 1;       // amount to decrease
               firetime =  sys.getTime() + 0.2;  // delay between decrements
           }


I had to split the post in two, as I was getting an 'invalid post' error...

_________________
"Leave me alone, I know what I'm doing..." Kimi Raikkonen


Top
 Profile  
 
 Post subject: Re: Realistic Weapon Recoil with Scripts[Help Needed]
PostPosted: Sun Jul 15, 2012 12:32 am 
Offline
is connecting to Doom3world.org

Joined: Wed Jul 11, 2012 2:51 am
Posts: 9
Thanks for the help. I'm still fine-tuning the values and it seems like a lot of trial and error getting the exact behavior desired.


Top
 Profile E-mail  
 
 Post subject: Re: Realistic Weapon Recoil with Scripts[Help Needed]
PostPosted: Tue Jul 31, 2012 7:56 pm 
Offline
The first 10 posts have been the best...

Joined: Wed Jun 06, 2012 5:56 pm
Posts: 22
All right, sorry for not replying to anyone, i was absent from these forums. While i do not have the code in front of me, let me explain this technique in full detail(the way i did it, that is!).
As i've posted already, in the fire state i use something like this:
If spread < (maximum spread here)
spread = spread + 1.
This increases it by 1 or the value you've set each time the Fire state is called. Holding down the button calls it multiple times, so this will work.
In the Idle state, my code was something like this:
If spread > (minimum spread here)
spread = spread-(very low value, because it will perform this operation very often)
if spread < (minimum spread here)
spread = (minimum spread here)

In the Idle state, when it calls the Reload state, i just set it to 0 because i can not think of a way to gradually decrease it while reloading(i've heard threading commands in weapon scripts can ruin things). It automatically sets it to the minimum spread after reloading of course.
I hope that helps.


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group