re-orienting velocity

Hello friends:

Right now I am making a script that allows objects to move on a fixed radius around a sphere, with arbitrary velocities and rotations. Currently, I am doing this to reorient the object as it flies around the sphere:

 var normal: Vector3 = (rigidbody.position - anchor.transform.position).normalized;
 var cross : Vector3 = Vector3.Cross(normal, transform.forward);
 rigidbody.position = anchor.transform.position + normal * orbitRadius;
 rigidbody.rotation = Quaternion.LookRotation(Vector3.Cross(cross, normal), normal);

However, when I add force to this object, the object’s velocity around the sphere slows down over time because the velocity is not reoriented in addition to the rigidbody’s position. Essentially, I believe that the velocity does not stay tangent to the sphere and I need it to. I am wondering how best to accomplish that.

Thanks!

Rather than doing those calculations you could use actual physics equations for gravity to apply the proper forces at specific radii. This becomes a little complicated.

You could just have the orbiting object use transform.LookAt(anchorTransform) and then adjust the velocity of the orbiting object in the orbitObject.right direction.

orbitObject.transform.LookAt(anchorTransform);
orbitObject.rigidbody.velocity = orbitObject.transform.right * desiredVelocity;