Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends Sprite
- var grid_size = 32
- var speed = 64 # speed in pixels per second
- var direction = Vector2(1, 0) # move in positive x direction, adapt this in your code for other directions
- var is_moving = false
- var moved_dist # keep track of how much we already moved
- func _fixed_process(delta):
- if Input.is_action_pressed("myInputAction") and !is_moving:
- #set direction here
- is_moving = true
- moved_dist = 0.0
- if is_moving:
- if (moved_dist < grid_size):
- #still have space, move on
- var offset = direction * speed * delta
- moved_dist += offset.length()
- set_pos(get_pos() + offset)
- else:
- #time to stop moving
- is_moving = false
- func _ready():
- set_fixed_process(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement