The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

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 count

func ready():

func newgoal():
direction = randi() % 4
steps = 50 + (randi() % 50)
count_steps = 0

func process(delta):
steps += 1
if countsteps > steps:
if direction == DOWN:
velocity.y = speed
rotationdegrees = 0
elif direction == RIGHT:
velocity.x = speed
degrees = -90
elif direction == UP:
velocity.y = -speed
rotationdegrees = 180
elif direction == LEFT:
velocity.x = -speed
degrees = 90
if velocity.length() > 0:

Godot version 3.5
in Engine by (12 points)

1 Answer

0 votes

Se postar o vídeo ou um gif ajudaria a ter mais informações do problema.

Talvez seja o "extends StaticBody2D" se fosse um area2D ou um kinematicBody2D pode ser que resolva o problema.

by (286 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.