#How to imitate jump by using sprite, not KinematicBody?
18 messages · Page 1 of 1 (latest)
the math is the same
instead of setting offset directly have a velocity vector
add velocity * delta to offset
do I need a move_and_slide method? its not working with a sprite
offset += velocity * delta
you don't need a method
although why not just use a kinematicbody2d?
I'm trying to imitate Z axis (2.5d game). Moving offset and collision seems like the simplest way to achieve my goal
extends Sprite
const GRAVITY = 1
const JUMPFORSE = -100
var velocity = Vector2()
func _process(delta):
offset.y = offset.y + GRAVITY
if offset.y > 0:
offset.y = 0
if Input.is_action_pressed("ui_accept"):
offset += velocity * delta
nothing happen when I click ui_accept
you want to add Gravity * delta instead of just gravity each frame
so it's not frame dependent
you also want to make sure that the offset doesn't go past a number
so
func _process(delta):
velocity.y += GRAVITY * delta
if Input.is_action_pressed("ui_accept"):
velocity.y = JUMPFORSE
offset += velocity * delta
Have you tried printing offset to ensure the value is changing as expected?
Wow, the speed of jump is slow (i'll look at that later), but it works just like I wanted it to. Thank you very much, thanks to you, I've moved on from this stalemate.