Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | juliafigueiredo |
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 move_direction = -1
var direction
var steps
var count_steps
func _ready():
randomize()
_new_goal()
func _new_goal():
direction = randi() % 4
steps = 50 + (randi() % 50)
count_steps = 0
func _process(delta):
count_steps += 1
if count_steps > steps:
_new_goal()
if direction == DOWN:
velocity.y = speed
rotation_degrees = 0
elif direction == RIGHT:
velocity.x = speed
rotation_degrees = -90
elif direction == UP:
velocity.y = -speed
rotation_degrees = 180
elif direction == LEFT:
velocity.x = -speed
rotation_degrees = 90
if velocity.length() > 0:
pass