Untitled
unknown
plain_text
a year ago
1.1 kB
8
Indexable
extends CharacterBody2D
@export var speed = 200
var vertical = true
var direction = Vector2.ZERO # Store direction as a Vector2
var timer = 69420
var final_time = 0.06
var collision = false
var facing = "where the snake is pointing towards"
func _process(delta):
facer()
moving()
timer += delta
func facer():
if Input.is_action_just_pressed("k_up") and not vertical:
vertical = true
direction = Vector2.UP
elif Input.is_action_just_pressed("k_down") and not vertical:
vertical = true
direction = Vector2.DOWN
elif Input.is_action_just_pressed("k_left") and vertical:
vertical = false
direction = Vector2.LEFT
elif Input.is_action_just_pressed("k_right") and vertical:
vertical = false
direction = Vector2.RIGHT
func moving():
if timer >= final_time and direction != Vector2.ZERO :
position += direction * 16
timer = 0
func interact():
if Input.is_action_just_pressed("k_action"):
#spawn another instance of the scene right behind it
pass
func _physics_process(delta):
move_and_slide() # Handles character movement based on velocity
Editor is loading...
Leave a Comment