Project a point into a shape/spatial (Box, sphere, etc.)

Hey, I’m working at the steer AI feature. I’m implementing the containment behaviour which basically refers to motion which is restricted to remain within a certain region.

I already know how to check If the agent future position will be inside a containment volume. If I know that the agent future position will be outside I need to move from that predicted position to the spatial/shape/geometry (or whatever that allows me to do that).

I have been looking for a useful method in the API but I’m a bit lost and I wanted to know If you know a method/class that allows you to project a point to the surface of a shape/spatial/geometry (or similar). That will allow me to calculate the offset from that projected point to the predicted location.

Thanks in advance.

Maybe the best solution is to cast a ray from the agent position and velocity direction, then we check for the collision with the node and we get that collision triangle. With that triangle I can just get his normal vector. Is there any other solution ?

@jesusmb1995 said: Maybe the best solution is to cast a ray from the agent position and velocity direction, then we check for the collision with the node and we get that collision triangle. With that triangle I can just get his normal vector. Is there any other solution ?

Maybe i understand wrong, but it sounds like you are looking for: CollisionResults.getClosestCollision().getContactPoint();

1 Like
@zzuegg said: Maybe i understand wrong, but it sounds like you are looking for: CollisionResults.getClosestCollision().getContactPoint();

Yep, I’m implementing the behaviour with “closestCollision.getContactNormal()” to get the normal and “closestCollision.getContactPoint()” to calculate the offset from the contact point. I will tell you If everything goes alright.

I was just wondering if there is other way to accomplish what I want in a simpler way but I think it is ok.

The behaviour is working.