The project: PlayCanvas 3D HTML5 Game Engine
(Jump 2 is currently loaded)
So I return seeking more help. I have two jump functions that I’d want to effectively combine but I’m not sure how to go about it. Jump implements an attribute that disallows air jumping and being able to continuously press the button to continue jumping. However, the jump doesn’t apply the impulse all the time there will be moments during the game the character won’t jump despite the animation playing.
Jump 2 fixes the problem of sometimes not working, however, the issue then becomes figuring out how to keep the player from continuously jumping and I doubt you can just ask someone to not press the button over and over.
Hi @Overbaked! I see you use a timer to determine if the player can jump again or not. I think I made this solution in another topic because this is easy to understand and implant. As far as I can see there are brackets on line 45 and 60 of your jump script that not belong there. This can be the reason that your jump function not work as expected.
I will look for the post you made earlier, however, even when removing the brackets the jump script still only works every so often. I’ve tried shortening the timer however that seems to break the script as a whole. I’ll try removing the timer since the parameters for when it needs to check should be enough.
I don’t see the problem that your jump is not applied correctly. But there is a problem that your jump animation is also started when you are already jumping. The reason for this is that you use the jump timer only for the actual force and not for the animation. So the animation start always when you use the jump button. To solve this problem follow the steps below.
var jumpTimer = 0; on line 2 of your jump script.
Replace your first statement in your animation script to
if (jump && jumpTimer <=0).
Remember that the timer is always the same, while the size of your jump is not always the same. As a result, the use of a timer is not optimal. Against this, the use collision detection is also not optimal because it also detects front and rear collisions. It would be best to use a downward raycast to check if your player has reached the ground. Unfortunately I can’t find a simple tutorial for using raycast in this way, so I’ll have to make an example myself when I have more time.