Well, I'm creating a game with blocks, like a maze. Where I have my character who must go through the enemies and reach the end of the stage.
But my enemy has a bug and sometimes invades the blocks and goes crazy. I'll post a video reporting the error and the code made.
I'm Brazilian so maybe my English isn't perfect.
This is my code:
extends StaticBody2D
const DOWN = 0
const RIGHT = 1
const UP = 2
const LEFT = 3
export var speed = 200
export var health = 1
var velocity = Vector2()
var movedirection = -1
var direction
var steps
var countsteps
func ready():
randomize()
_newgoal()
func newgoal():
direction = randi() % 4
steps = 50 + (randi() % 50)
count_steps = 0
func process(delta):
countsteps += 1
if countsteps > steps:
_newgoal()
if direction == DOWN:
velocity.y = speed
rotationdegrees = 0
elif direction == RIGHT:
velocity.x = speed
rotationdegrees = -90
elif direction == UP:
velocity.y = -speed
rotationdegrees = 180
elif direction == LEFT:
velocity.x = -speed
rotationdegrees = 90
if velocity.length() > 0:
pass