Hey there!
I'm working on a very simple isometric c# strategy game and I have a raycast projecting from the camera to the mouse point. This part is all working well and good, but it's falling apart in the "collision mask" department.
What I am trying to accomplish is the ability to "ignore" objects other than the floor, the thing I always want my click to "target" as the destination for my player character.
For the life of me, I cannot quite figure out how this all works. I've been reading the documentation on raycasting all day and seemingly making little to no headway. This is what I have so far, which works perfectly fine without obstacles... so not particularly useful atm!
public Vector3 MousePointRaycast()
{
Vector3 pointPosition;
Vector3 from = mainCam.ProjectRayOrigin(GetViewport().GetMousePosition());
Vector3 to = from + mainCam.ProjectRayNormal(GetViewport().GetMousePosition()) * rayLength;
//Create Querry
PhysicsRayQueryParameters3D rayQuery = new PhysicsRayQueryParameters3D()
{
From = from,
To = to,
CollisionMask = 4294967295,
Exclude = [GetRid()]
};
//Determine if the querry is a hit or not
PhysicsDirectSpaceState3D space = GetWorld3D().DirectSpaceState;
Variant newVal;
space.IntersectRay(rayQuery).TryGetValue("position", out newVal);
GD.Print ("Physics Querry is " + newVal.ToString());
//Use collision as target position
pointPosition = (Vector3)newVal;
GD.Print ("Target is " + pointPosition);
return pointPosition;
}