All gameObjects should have a float declared named gravity and when climbing it is set to 0.0f, otherwise it is set to 0.5f or something similar
put this in your games update method before doing movement
| player.gravityOn(); // could be player.gravity = true; |
| if(ladderbox.Intersects(playerbox)) |
| player.gravityOff(); // could be player.gravity = false; |
another way to use ladders is to make player move up by gravity*2 when climbing requiring a climbing variable usually set to false
;
you can use the same code for a jetpack btw just think a ladder code above is linear speed, a jetpack requires velocity so for a jetpack you would have a maximum velocity (proba]bly in a Vector2 or Point) and keep adding to the .Y until velocity.Y >= maxVelocity.Y, then at the end
| if (velocity.Y > maxVelocity.Y){ velocity.Y = maxVelocity.Y; } |
also a jetpack requires no collision however checking the player does not collide with the walls is a good idea, I made a few jetpack games where fi the players velocity was too high when they hit a wall they lost health and lives! just some extra food for thought