-The goobers in question: Player, Enemy (moves towards player)
-What isn’t happening: I’m trying to make a raycast to check if an object is between the enemy and player, from the enemy’s script, for the enemy to detect the player.
So I’ve tried a ton of different ways of casting an intersect ray but it never works. When I stopped getting errors the cast would output at “random” (but consistent) position somewhere near world origin (but not at world origin). I finally got it to actually output objects, but it would output a seemingly random output at a particular position (When both were in a pretty small area a bit positive on x and z, it would output a “random” one of the walls I had there, but nothing was between player and enemy.). Something being between player and enemy had no effect on the output. I just need an intersect ray that works with two moving objects, to check if anything is between them
Well I had it just set the var in the physics loop so it just remade the raycast each physics frame, but I redid the code so much I dunno, I also thought I could use a shapecast (Which I can’t because of how that works) so I deleted the code. So yeah I just need any way to get the raycast to work, because I can’t find an answer on how to. (Note the raycast is code based, not node based)
It’s hard to know what went wrong. A common issue with raycasts is assuming it’s target_position property is in global space. It actually checks collisions pointing in target_position’s direction and length. So properly setting this every frame would look like this:
extends RayCast3D
@export var target: Node3D
func _physics_process(delta: float) -> void:
var diff = target.global_position - self.global_position
target_position = diff
When I did that it started consistently returning values pertaining to the player, but I can’t get it to check if it isn’t the player (it’s actually outputting the objects it collides with now, but as a weird string with a lot in it now)
That above is the output from “print(result.get(n))” and below is the statement with error
How do I get the object in dictionary rather than the raycast converting the object to this weird string?
Ok, I got it retuning an object, and when I start the project it returns the player!
Great! Solved, right?
I step back like 2 (meters?) and it starts detecting the ground. The ground is not between me and the enemy, and also, I checked by renaming the ground and I saw the name in the “print()”
I think it’s casting down?