Weapon Sway
by none · in Torque Game Engine · 07/29/2010 (12:27 am) · 16 replies
I know this has been asked a thousand times, but how do I get my weapon to sway? I know how to animate it, but I have not been able to find a solution that works for multiplayer.
#2
07/30/2010 (3:34 am)
Yea, I'm using the standard ShapeBaseImages, and I checked out Bryce's resource, but he stated that it wouldn't work for multiplayer, and my game is entirely multiplayer :/. I planned on handling accuracy a different way, where the accuracy would change depending on your stance. For example prone would be most accurate, walking would be least accurate.
#3
weapon sway is a very tricky issue because of the way ShapeBaseImages work - they don't actually exist, and they look different when viewing from first and third person.
The way I see it, there are two wildly different routes to take.
1. Animate the weapon itself somehow to bob while moving. I'd recommend adding a new animation thread in ShapeBaseImage and playing a blended animation that jiggles the image's root node around. This way other threads can happen at the same time as the weapon is moving. Some care may have to be taken to only play this animation on the client which the weapon is attached to. Other clients will just see the weapon attached to the character's hands. Then when you create projectiles, it's simple to add random velocity to make them scatter depending on the character's velocity. I'm sure there are good resources for that out there.
2. What I did. Get rid of ShapeBaseImages, animate the player fully at all times, and very simply attach the weapon to the character's hands. This is a more simulated approach rather than faked. It also requires quite a bit of understanding and modification of the source, and a lot of time and effort :P. It was worth it to me.
07/30/2010 (7:00 am)
Ah, sorry - didn't catch that in the resource.weapon sway is a very tricky issue because of the way ShapeBaseImages work - they don't actually exist, and they look different when viewing from first and third person.
The way I see it, there are two wildly different routes to take.
1. Animate the weapon itself somehow to bob while moving. I'd recommend adding a new animation thread in ShapeBaseImage and playing a blended animation that jiggles the image's root node around. This way other threads can happen at the same time as the weapon is moving. Some care may have to be taken to only play this animation on the client which the weapon is attached to. Other clients will just see the weapon attached to the character's hands. Then when you create projectiles, it's simple to add random velocity to make them scatter depending on the character's velocity. I'm sure there are good resources for that out there.
2. What I did. Get rid of ShapeBaseImages, animate the player fully at all times, and very simply attach the weapon to the character's hands. This is a more simulated approach rather than faked. It also requires quite a bit of understanding and modification of the source, and a lot of time and effort :P. It was worth it to me.
#4
07/30/2010 (3:26 pm)
Alright, I'll give it a try haha, but what about rendering first person? If I do that and animate the player with all the animations and use hiding of meshes, wouldn't weapon sway just be a matter of animating the player?
#6
07/30/2010 (11:08 pm)
Alright, thank you very much Daniel, I think I'll use this resource. Do I need to use the hide mesh resource? I ask this because I have successfully hidden a mesh until a certain frame with no resource. Thank you again for all of your help!
#7
07/30/2010 (11:59 pm)
P.S. Now that the models would be directly modeled onto the character, how do I decide which animations play for the weapons states? Can I call player animation from the weapon script? If so, can you give me an example?
#8
Beware, though, that this method means your arm animations have to be pretty spot-on, especially for things like iron-sights aiming, unless you do a separate client-side effect for that. I don't mind having to do this, but it is a lot more effort than using eye offsets.
07/31/2010 (3:51 am)
Quote:Do I need to use the hide mesh resource?What for? It's certainly a good addition, but what do you mean in this context?
Quote:how do I decide which animations play for the weapons states?As in, for things like reloading that require the character to do something? Make use of the state's 'script' field to call a function like onReload (just like how onFire works) which makes your character play an appropriate thread.
Beware, though, that this method means your arm animations have to be pretty spot-on, especially for things like iron-sights aiming, unless you do a separate client-side effect for that. I don't mind having to do this, but it is a lot more effort than using eye offsets.
#9
I know how call weapon animations from the state field but how do I call character animations? I'm really confused as to how having the gun modeled onto the player even works since you wouldn't be able to use a mountPoint or muzzlePoint...
07/31/2010 (4:23 am)
For the first part I meant, if I'm modeling all of the weapons onto the player, don't I need to hind the weapons until their animation? Because I won't be mounting weapons on any more right?I know how call weapon animations from the state field but how do I call character animations? I'm really confused as to how having the gun modeled onto the player even works since you wouldn't be able to use a mountPoint or muzzlePoint...
#10
It's quite feasible to actually still use ShapeBaseImages - you just won't need eye offsets, etcetera. I guess I phrased that badly.
But I do like the object-oriented-ness of having weapons be objects too. It especially works since I'm going for more RPGish gameplay where lots of items will be existing independent of characters. But depending on your game design that may not be useful.
07/31/2010 (5:54 am)
Oh - by doing away with ShapeBaseImages, I meant that I'm using actual objects as opposed to Images mounted on an object. I've based my new Item class off RigidShape.It's quite feasible to actually still use ShapeBaseImages - you just won't need eye offsets, etcetera. I guess I phrased that badly.
But I do like the object-oriented-ness of having weapons be objects too. It especially works since I'm going for more RPGish gameplay where lots of items will be existing independent of characters. But depending on your game design that may not be useful.
#11
07/31/2010 (4:05 pm)
I'm making a game in between the earlier Battlefield games and Call of Duty. So basically if I use the rendering first person technique, I need to make sure that the animation of the gun syncs up to the animation of the player? Sorry I'm no good at the non-art side of torque haha. So basically since I'm no good at coding, I probably don't have the experience to rid of the ShapeBaseImage. Do you think it would be easier for me to keep using arms in first person? If I use the renderfirstperson, how do I sync up the player animation and weapon animation? I'm sorry, thank you for your patience, I'm new to this part.
#12
08/01/2010 (3:28 am)
With Jacob Dankovchik's resource, your player will animate fully all the time. Then you just mount the weapon image to the player's hand. The weapon shouldn't animate at all - it just follows the natural motion of the mount node it's attached to, which you need to animate as part of your player. If you go ahead and implement the resource, you'll see that not much changes from usual - although your weapon will probably now be pretty inaccurate, unless your animations are perfect already.
#13
08/01/2010 (5:43 am)
If the weapon does not get animated at all, how would reload animations work?
#14
08/01/2010 (10:40 am)
Well, you might need animations for things like that! Without having to worry about 'bobbing around' animations, you can just use the method I described earlier - when the weapon goes into its reload state, call an onReload function which causes the player's arms to animate correctly.
#15
08/01/2010 (3:04 pm)
Alright I think I get it now haha, I'll reply if I have any issues. What lines of script would be used to call a player animation in a weapon script? I appreciate all of the help Daniel. Thank you very much.
#16
Obviously you'll want to scale the entire effect based on velocity so that the sway starts slow and easy and builds up as the player reaches maximum run speed.
08/05/2010 (7:19 pm)
If we're talking about first person renders, I would go hijack the code for eyeOffset and manually code in a sway effect there based on the mounted object's current velocity. That's how I handle iron sights -- when the engine goes to set the render position for first person and looks for eyeOffset, I substitute a value I added -- sightsOffset -- for eyeOffset, moving the weapon model to the center of the screen and closer to the camera. To produce an animation instead of a sudden change in location you could just hook into the sim time here. A left/right or up/down sway would basically be a matter of adding the value of a sin wave (use the time in ms as the input and scale appropriately to slow it down/speed it up as needed) to the X and Y eyeOffset values. Scale the output of the sin as needed to produce the correct amplitude. Obviously you'll want to scale the entire effect based on velocity so that the sway starts slow and easy and builds up as the player reaches maximum run speed.
Torque Owner Daniel Buckmaster
T3D Steering Committee