Altering Player Movement to Finish Walk Cycle
by MMPlus (Greg) · in Torque Game Engine · 09/23/2007 (7:10 am) · 3 replies
I'm trying to get my player to complete it's animation cycle and movement after the directional movement key has been released (so the character takes a complete step). I don't want the player to stop moving the instant the key is released, nor do I want the motion to transition from the walk animation to the root animation. I would prefer it to function more like the jump button so that the movement and animation complete and stop, or keep repeating if the key is not released.
I'm very new to Torque and somewhat of a novice programmer. I've been tracing through the C++ code to find out what functions call other functions and so forth, so I think I'm beginning to understand the architecture of the engine as far as the player controls are concerned. However, I'm not sure why jumping is a "trigger" and directional movement is not, or what a trigger is even for and why they are handled differently. Is a trigger the key to doing what I want to do?
I'm very new to Torque and somewhat of a novice programmer. I've been tracing through the C++ code to find out what functions call other functions and so forth, so I think I'm beginning to understand the architecture of the engine as far as the player controls are concerned. However, I'm not sure why jumping is a "trigger" and directional movement is not, or what a trigger is even for and why they are handled differently. Is a trigger the key to doing what I want to do?
About the author
#2
One thing does pop into mind though, Torque supports the use of triggers in the animation track. It uses these to dictate when each foot has come into contact with the ground and plays a dust emitter/decal. You could possibly swipe this code and rework it so that you place a trigger at the start of the animation and check whether the player is on that frame - if yes walkAnimFinished $= true else false etc.
09/23/2007 (8:16 pm)
As far as I know Torque doesn't have any stock code that allows one to obtain the frame number of an animation and trigger events based off that.One thing does pop into mind though, Torque supports the use of triggers in the animation track. It uses these to dictate when each foot has come into contact with the ground and plays a dust emitter/decal. You could possibly swipe this code and rework it so that you place a trigger at the start of the animation and check whether the player is on that frame - if yes walkAnimFinished $= true else false etc.
#3
Through experimenting I figured out that in gameConnectionMoves.cc if I add another number to curMove.x or curMove.y the character will automatically start walking because the value is now non-zero. So I added some code to increment a count until it reaches the number of frames in the walk animation. Once that count is reached, the number I add to curMove.x or curMove.y is set to zero again, which stops the animation and movement from automatically incrementing. Likewise, I set the count to begin once any of the direction variables (mRightAction, mLeftAction, etc.) for movement becomes non-zero and off it goes!
09/24/2007 (8:33 pm)
It looks like I'm on my way to solving my own problem. I suppose it's a bit of a hack, but it seems to be working.Through experimenting I figured out that in gameConnectionMoves.cc if I add another number to curMove.x or curMove.y the character will automatically start walking because the value is now non-zero. So I added some code to increment a count until it reaches the number of frames in the walk animation. Once that count is reached, the number I add to curMove.x or curMove.y is set to zero again, which stops the animation and movement from automatically incrementing. Likewise, I set the count to begin once any of the direction variables (mRightAction, mLeftAction, etc.) for movement becomes non-zero and off it goes!
Torque Owner MMPlus (Greg)
I'm looking for how the program distinguishes between a keydown and a keyup event and how that relates to the walk cycle. I've found the updateMove and updatePosition and updateAnimation functions in the player.cc file, I've found where animation transitions are set to go off when a player stops moving and I've successfully experimented with turning that off. I'm looking for whatever code bridges the gap between the event manager that records the keyboard inputs and the player class that's controlling how and when animations and movement are happening.
What I'm REALLY hoping for is that I'm over thinking the problem and I'm digging much more into all these functions than I need to be. What I need is code that would do the following:
on keyUp, if walkAnimation is not finished, then keepPlaying = true
if keep playing = true, then continue advancing movement and ignore other keyboard requests for movement
if walkAnimation = finished, then keepPlaying = false