glitchy jump code?

Blitz3D Forums/Blitz3D Beginners Area/glitchy jump code?

Guy Fawkes(Posted 2010) [#1]
What's up w/ this code? When I turn bounce off, it doesn't let me jump. But when I turn it on, if u bounce then try to jump, it sometimes allows u to jump twice..

I need it to STOP bouncing, and ONLY jump one time:




Guy Fawkes(Posted 2010) [#2]
Does anyone know what is going on w/ this code?


Serpent(Posted 2010) [#3]
When bouncing is turned off, it seems that when you jump the jumping is stopped just slightly above the bottom of the cube. If you tab spacebar and can get through this weird barrier the jump works normally. It seems that the cube collides with something slightly above the ground. When the bounce factor is turned down low you notice this because it stops the jump completely. However, when the bounce factor is 0.8 (which appears to be what you have been using) you don't notice the reduction in jump speed.

If you set the bounce factor to 0.5, you can see two things out of the ordinary. First of all, when you jump, you don't jump very high because every frame that the cube collides with the invisible barrier above the surface reduces the Y speed by a factor of 0.5. Also, you can jump a second time in mid-air, indicating that the flag 'jumping' has been set to 0 (meaning that a collision has taken place).


Serpent(Posted 2010) [#4]
When you disable collisions with the level, everything works fine (apart from the falling the floor etc.) and I think i know why...


Serpent(Posted 2010) [#5]
I've found the problem.

Calling UpdateWorld calculates all collisions, etc.
UpdateWorld in this case was being called AFTER the code that dealt with collisions. Effectively, all the code in the program regarding collisions was one frame out of sync.
Whenever you would jump, the program would deal with the collisions from the frame before and think that the player is still in contact with the floor (because although the player had moved, collisions still hadn't been updated). The program would execute the bounce code. When the bounce factor is set to something high like 0.8, this bounce that occurs one frame after the jump is unnoticable. However, when you tried to disable bouncing completely, whenever you jump the program remembers the collisions from the previous frame and multiplies the Y speed by 0 or 0.1 or whatever you set the bounce factor to.

The solution to the problem is to simply move the 'UpdateWorld' in the main loop to before where the do_collisions() function is called.




Serpent(Posted 2010) [#6]
Now you should be able to set the bounce factor to whatever you want and it will not affect the jumping at all.