Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Meno |
Hellow, i’m new in the godot community and for a game jam, i would like to make a small puzzle game where you have to avoid enemies. Thoses enemies are making some back and forth in a restricted area.
The problem’s here is that i would like between each movement, the enemy have to wait a small amount of time a little like in Cadence of hyrule.
I tried to code this but it don’t really work
Thanks (sorry if there’s some mistakes i’m french)
The code :
`extends KinematicBody2D
export var direction = 1 #1 = right, -1 = left
export var speed = 32 #The size of one tile, the distance that the enemy have to travel
export var stamina = 4 #The number of tile it can travel
var max_stamina = stamina * speed
var curent_stamina = 0 #To know how much tile it have already travel
func _physics_process(delta):
move()
func move():
var vel = Vector2()
if curent_stamina < max_stamina:
curent_stamina = curent_stamina + 32 #It travel 1 tile for now
vel.x = speed * direction
vel = move_and_slide(vel)
elif curent_stamina == max_stamina: #If it travel the max stamina, it changes his direction
direction = direction * -1
curent_stamina = 0
`