|
I'd like to make my gun bob up and down a bit on my fps whilst I'm moving. Could someone explain the basic way I would go about doing this? I've got an animation that plays when I fire so I know a little bit about it but I'm not quite sure on how to find out when the player is moving in code. Thanks
(comments are locked)
|
|
If you've already got your bob animation in the gun then all you need to do is add another script to the gun that says something like
this might be a problem if you want to walk forward and shoot at the same time so add an else clause to only play the bob animation when not shooting. Alternatively you can adjust the position of the gun using a sin wave adjusting frequency and amplitude based on movement speed. something like:
bob speed needs to be incremented every frame for a smooth motion and you need to centre the gun when you stop. You can also do side to side motion or twisting much the same way. The advantage of this method over animation is that it's directly linked to movement speed but on the other hand it's more fiddly to get it to look right. EDIT Using your example:
You can also use animation blends to transition between animations Thanks, I have tried the first way and like you say, it messes up the fire animation. I tried to write my own code but I think i've got it badly wrong. Here is my attempt: var fireclip; function Update () { if (Input.GetButton("Fire1")) { animation.Play("AnimationEnfield"); fireclip = true; return; } if(Input.GetKey("w") && fireclip == false){ animation.Play("AnimationEnfield2"); } else { return; } } The fire animation still works but the walking one doesnt - I'm not sure how to do this but I'm pretty sure I've got it completely wrong!
Apr 30 '10 at 11:59 AM
Pure Phase
(comments are locked)
|
|
Sorry, I'll put that as an answer so it's easier to read does your fireclip ever become false? add and else after the if statement with fireclip = false
Apr 30 '10 at 01:05 PM
spinaljack
better to edit your question rather than post another answer
Apr 30 '10 at 01:10 PM
spinaljack
Noted, I wondered how I should respond. I think I've got it working now thanks!
Apr 30 '10 at 02:20 PM
Pure Phase
(comments are locked)
|
