Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends CharacterBody2D
- @export var speed = 200.0 # Movement speed of the player
- func _process(delta: float) -> void:
- var direction = Vector2.ZERO # Initialize the movement direction
- # Handle keyboard input for movement
- if Input.is_action_pressed("ui_right"):
- direction.x += 1
- if Input.is_action_pressed("ui_left"):
- direction.x -= 1
- if Input.is_action_pressed("ui_down"):
- direction.y += 1
- if Input.is_action_pressed("ui_up"):
- direction.y -= 1
- # Normalize direction and multiply by speed for consistent movement
- velocity = direction.normalized() * speed
- # Move the player using the calculated velocity
- move_and_slide()
Advertisement
Add Comment
Please, Sign In to add comment