Godot Version
4.2.2.stable.mono
Question
Hello everyone, I’m trying to detect objects that are between the camera and player. To do this I want to raycast from the camera to the player and pick up colliders in between the two.
I’m not sure how this works with orthogonal though. This is the code I have right now
public override void _PhysicsProcess(double delta)
{
var ray_length = 1000;
var from = camera.ProjectRayOrigin(Vector2.Zero);
var to = from + character.GlobalTransform.Origin * ray_length;
var space = GetWorld3D().DirectSpaceState;
var ray_query = PhysicsRayQueryParameters3D.Create(from, to);
ray_query.From = from;
ray_query.To = to;
ray_query.CollideWithAreas = true;
ray_query.Exclude.Add(character.GetRid());
if(character is Player player)
{
ray_query.Exclude = player.exclude;
}
var result = space.IntersectRay(ray_query);
}
}
I’m not sure how the camera.ProjectRayOrigin works with an orthogonal camera, so I don’t know exactly what to pass ProjectRayOrigin.
If anyone has experience raycasting from an orthogonal camera, or has any insight that would be helpful please leave a reply!