#Programmatically raycast with body with collision failing?

3 messages · Page 1 of 1 (latest)

noble spear
#

the lines are the ray cast, and the collision boxes are the boxes

#
var body = new StaticBody3D();
body.Name = "Floor";

var area = new Area3D();
area.Position = new Vector3(0, 0.01f, 0);
body.AddChild(area);

var collisionShape = new CollisionShape3D();

var boxShape = new BoxShape3D();
boxShape.Size = new Vector3(1.0f, 1.01f, 1.0f);
collisionShape.Shape = boxShape;
collisionShape.Disabled = false;
area.AddChild(collisionShape);

body.CollisionLayer = 1;
body.CollisionMask = 1;

is my setup

#
Vector3 rayOrigin = camera.ProjectRayOrigin(ClickPosition);
Vector3 rayDirection = camera.ProjectRayNormal(ClickPosition);

PhysicsDirectSpaceState3D spaceState = camera.GetWorld3D().DirectSpaceState;
Vector3 rayEnd = rayOrigin + rayDirection * 1000;
var query = new PhysicsRayQueryParameters3D()
{
  From = rayOrigin,
  To = rayEnd,
  CollisionMask = 1,
};
var hits = spaceState.IntersectRay(query);