- Home /
Local FPS Gravity Changing Lerp
Right now I'm working on a small game where the player can change the direction of gravity. When they do this I lerp from transform.up to vector3.right * -1. This should work locally. However whenever I face a different direction, I am snapped back to looking forward and then I am lerped from this position. What I need is for lerp to respect my current orientation and transform my .up from into my local right. Rather than snapping me back to the global right and then Lerping me.
transform.up = Vector3.Lerp(transform.up,targetRight,Time.fixedDeltaTime* damping);
With targetRight = Vector3.right* -1 and damping is just a float(6) Does anyone know how to accomplish this? Thanks for reading.
An interesting question, but I cannot completely visualize the problem. I suspect the issue as to do with the way Quaternions work, and you need to rework your code to use Quaternion.LookRotation(), or Quaternion.AngleAxis() to do your rotation.
The rest of the script and/or a link to a sample project would be a big help figuring this one out.
Vector3.right will always point along the world's right. Try using transform.right. Also, you can just negate a Vector with the negative sign (-) ins$$anonymous$$d of multiplying by -1. So (your code looks like US),
var initialUp : Vector3 = trasform.up;
var initialLeft : Vector3 = -trasform.right;
var lerpValue : float = 0;
while (lerpValue <= 1)
{
lerpValue += Time.fixedDeltaTime * damping;
transform.up = Vector3.Lerp(initialUp, initialLeft, lerpValue);
yield return;
}
Thanks for the fast reply. I'll try this out and report back soon.