Hello, I’ve been playing with the third person movement and I want to add other controls. I have added the jump animation, but it only makes the character go up and plays walking animation instead of jump animation.
@churiboii Initially I see that you have the following issue in the playerMovement script. Please correct the bottom direction to ‘yDirection’. Currently you have two z’s.
this.entity.anim.setFloat('xDirection', x); this.entity.anim.setFloat('zDirection', z); this.entity.anim.setFloat('zDirection', y);
It looks like the animation state graph should work fine with the above correction but, have not forked your project.
Thank you! That worked but the animation keeps on looping and does not stop on jumping upwards when pressed. Should I make a separate script for the jump and use onCollision or is there a way to make it jump once using the current code?
@churiboii Not sure if you need to make a separate script. There are several ways of doing what you would like to do inside of playerMovement. One way is to give your plane a tag name of ground. When your character is on the ground you can allow all movements to occur. If the player hits jump, you can stop updating x and z. When the player collision detects it is on the ground again then you can enable all again. You could also disable all x and z when the player hits jump and when jump is released it can be enabled again. I also noticed that I can hit jump several times while in the air and it keeps climbing. This is a common issue with most people. Once again you could use a flag that would disallow any more jump key presses while not on the ground. Hope this helps.
I made the character jump once but the animation does not work, so I changed it to boolean but again it keeps looping. How do I make it play once?
You set a boolean to
true when the player is jumping for the first time, but you never set it back to
false. As long as this boolean is
true, the animation is switching between idle and jump.
Another problem is that your jump animation will never completed, because your other animation(s) overrides it from ANY state.
Unfortunately, I don’t know of a quick fix. I’m afraid you need to rethink the logic and apply it in the Anim State Graph.