Godot Version
v4.2.1.stable.mono.official [b09f793f5]
Question
I’m doing a raycast, and trying to check wether it has hit anything.
Code:
public object ShootRay(uint collisionMask)
{
Vector2 mousePos = GetViewport().GetMousePosition();
var rayLen = 1000f;
var from = cam.ProjectRayOrigin(mousePos);
var to = from + (cam.ProjectRayNormal(mousePos) * rayLen);
var space = GetWorld3D().DirectSpaceState;
var query = PhysicsRayQueryParameters3D.Create(from, to, collisionMask);
var result = space.IntersectRay(query);
if (result.IsEmpty()) return null;
//GD.Print(result);
return result;
}
I get this error:
Error CS1929: ‘Dictionary’ does not contain a definition for ‘IsEmpty’ and the best extension method overload ‘GD.IsEmpty(byte)’ requires a receiver of type ‘byte’
I don’t really understand how to use GD.IsEmpty(), or if it even applies to this situation. Can anyone explain to me how it works, or if there are any alternatives for checking wether the raycast hit something? (Also I’m pretty sure that returning the result as an object is wrong, so I would appreciate some help on that front too)