How to get nearest point on scene model mesh to player model mesh in urho3d?
I want to make gravity like in mario galaxy. I tried to get direction to mesh center, but if I have complicated geometry, I think I need closest point on mesh and get normal of it instead of mesh center. I think I need perpendicular direction to the scene surface.
void Character::RaycastToWorld()
{
RigidBody* body = GetComponent<RigidBody>();
Vector3 bodyUpPos = body->GetPosition();
Vector3 castRayVec = worldNode_->GetWorldPosition() - bodyUpPos;
Vector3 castRayN = castRayVec.Normalized();
curDistToWorld_ = castRayVec.Length();
prevDirToCenterWorld_ = dirToCenterWorld_;
PhysicsRaycastResult result;
GetScene()->GetComponent<PhysicsWorld>()->RaycastSingle(result, Ray(bodyUpPos, castRayN), curDistToWorld_, ColMask_WorldRayCast);
if (result.body_)
{
dirToCenterWorld_ = result.normal_ * -1.0f;
curDistToWorld_ = result.distance_;
}
}