Godot Version
func _process(delta):
var Raycasts = [$Up, $Down, $Right, $Left]
if [Raycasts].is_colliding():
print(“Collided”)
func _process(delta):
var Raycasts = [$Up, $Down, $Right, $Left]
if [Raycasts].is_colliding():
print(“Collided”)
use a for loop! The break
keyword can also be helpful if you just want the first collision.
for ray in Raycasts:
if ray.is_colliding():
print("Collided")
break #stops after first hit
Should the loop be in a func _process(delta): loop?
I tried it like this:
func _process(delta):
var Raycasts = [$Up, $Down, $Right, $Left]
for ray in Raycasts:
if ray.is_colliding():
print("Collided")
break
But it didnt work
Why didn’t it work? Could you show more about your test scene, like the raycast properties and what it is supposed to be hitting?
It would be best to declare var RayCasts
outside of the _process
function so that it doesn’t re-create the Array every frame.
var Raycasts = [$Up, $Down, $Right, $Left]
func _process(delta):
**for ray in Raycasts:**
if ray.is_colliding():
print("Collided")
break
Then I get an error cause the func does not know what the Raycasts array is
Where the two ** is, is where it shows a red line
You need to remove the indentation:
var Raycasts = [$Up, $Down, $Right, $Left]
func _process(delta):
for ray in Raycasts:
if ray.is_colliding():
print("Collided")
break
Now It I get an error that says that the .is_colliding
is null in instance
Then add @onready
, and make sure those nodes actually exist
the lines is now red
got this error: Unindent doesn’t match the previous indentation level.
Please show your code
ah wait
@onready var Raycasts = [$Up, $Down, $Right, $Left]
func _process(delta):
for ray in Raycasts:
if ray.is_colliding():
print("Collided")
break
nothing happens when the raycasts hit a wall
And you are sure the raycasts are actually correctly set up?
Here is a picture:
I mean are they aimed correctly and are their layers set up?