I am trying to create an object that accelerates around a sphere. In the object’s update function, I apply a force to it that it parallel to its forward. I also have this code to keep the object at a constant distance from the sphere and parallel to the sphere’s surface. However, no acceleration occurs because the velocity is not conserved in spherical coordinates. To fix this I tried adding the commented lines, which are supposed to first store the current local velocity, and after the position and rotation change, set it again to the previous value. However, it only produces extreme jerkiness. What is the best method?
var hit : RaycastHit;
var newForward : Vector3;
if (surfaceCol.Raycast(new Ray(thisTransform.position, surface.position - thisTransform.position), hit, 100)) {
newForward = Vector3.Cross(hit.normal, thisTransform.right);
// var oldVel = thisTransform.InverseTransformDirection(thisBody.velocity);
thisTransform.LookAt(thisTransform.position + newForward * 50, hit.normal);
thisTransform.position = hit.point + hit.normal * height;
// thisBody.velocity = thisTransform.TransformDirection(oldVel);
}