Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends CharacterBody2D
- var speed: float = 100 # Speed of the player in pixels per second
- func _physics_process(delta):
- # Reset velocity at the start of every frame
- velocity.x = 0
- velocity.y = 0
- # Handle arrow key input
- if Input.is_key_pressed(KEY_RIGHT):
- velocity.x += speed
- if Input.is_key_pressed(KEY_LEFT):
- velocity.x -= speed
- if Input.is_key_pressed(KEY_UP):
- velocity.y -= speed
- if Input.is_key_pressed(KEY_DOWN):
- velocity.y += speed
- # Apply velocity to move the player and handle collisions
- move_and_slide()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement