1. In function “jump” I set up vertical speed of player to -const.jump_speed
1 | player.vy = -const.jump_speed |
2. Function “main_loop” increase this value
1 | player.vx, player.vy = player.vx+player.gx+player.ax, player.vy+player.gy+player.ay |
player.gy – gravity
player.ay – any another force
3. I increase gravity depending on horizontal speed of player (only if player.vy>0 eg in state “fall”)
1 2 | local fall_gravity_k_dynamic = player.vx/const.start_speed if player.vy>0 then player.vy = player.vy+(player.gy+player.ay)*(const.fall_gravity_k-1)*fall_gravity_k_dynamic end |
4. Touch sets up vertical speed. Touch and keep sets up speed multiple times (each cycle) over period of max_jump_time.
1 2 3 | if touched and system.getTimer()-jump_start_time<const.max_jump_time and player.state=="jump" then player.vy = -const.jump_speed end |
5. Here is jump and double jump calls. Double jump can be called only once. It can be used in fly eg in states “fall” and “jump”. player.double_jump_used controls it.
1 2 3 4 5 6 | if player.state=="run" then jump("jump") elseif player.state=="jump" or player.state=="fall" and not player.double_jump_used then jump("double_jump") player.double_jump_used = true end |
Hi, can I know why you set the x value of the player, but the player is in fact only move in +y and -y direction?
Thanks.
How do you make the animated .png file for the rabbit?