jefify
1
I’m trying to code an enemy that switches it path from left to right and right to left when facing a wall in 2D
func _process(delta: float) → void:
if Ray_cast_Right.is_colliding():
Direction = -1
if Ray_cast_Left.is_colliding():
Direction = 1
position.x += Direction * SPEED * delta
Whats happening when you run this code?
jefify
3
it gives me 2 errors
Identifier “Ray_cast_Right” not declared in the current scope.
Identifier “Ray_cast_Left” not declared in the current scope.
That’s because you did not declare the raycasts as variables.
1 Like
Nash
5
You can click and drag the ray cast node on to your code and hold ctrl before releasing, then you can do the following.
@onready var ray_cast_left = Ray_cast_left #node name
func _process(delta):
if ray_cast_left.is_colliding():
direction = 1
Do the same for the right ray cast
1 Like
system
Closed
6
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.