- Home /
Use Vector Lerp or other to move back with arc
Hi guys can you tell me how can I use Vector Lerp to move back to start position with arc. Check image below :
When we press button gameobject move from other position to start position but back with arc like on image.Can you help me with this ?
I think you will have to write your own function. Lerp by itself cannot do this.
LERP stands for Linear intER$$anonymous$$te, which implies moving in a straight line. You probably want some sort of spline function which will allow you to follow a curve through a given set of points.
Answer by robertbu · Jan 15, 2013 at 01:46 AM
There are a number of ways to creating this movement. Dave Carlile's suggestion of using a spline can easily be implemented in iTween (a free addon package to Unity). Probably other packages as well. Slerp will do the job, but you might have trouble hitting percise values like z=1 if that is what you are looking for. If you wanted more control of the arcs you could handle the movement yourself with sine curves. Something line:
void MoveObject(float fFraction)
{
Vector3 v3Delta = v3EndPos - v3StartPos;
Vector3 v3Pos = v3StartPos;
v3Pos.x += v3Delta.x * fFraction;
v3Pos.y += v3Delta.y * fFraction + Mathf.Sin (fFraction * Mathf.PI) * fYFactor;
v3Pos.z += v3Delta.z * fFraction + Mathf.Sin (fFraction * Mathf.PI) * fZFactor;
transform.position = v3Pos;
}
This would be called by Update(). fFraction is the fraction of the way between start and end to place the object. fYFactor and fZFactor are the amount you want to offset at the max in the Y and Z directions.
there is no documentation of spline in iTween so can you help me out where i can find this
Answer by Wolfram · Jan 14, 2013 at 01:47 PM
If a circular arc is OK, you can use Vector3.Slerp with an origin between your two positions and with negative Z.
Your answer
Follow this Question
Related Questions
Move child gameobject in x axis (Lerp) 1 Answer
Can I move a component from one GameObject to another in script? 1 Answer
C#: Move an object along one axis at time 3 Answers
How to move an object from point A to point B with one key press 3 Answers
Detect when a UI button is not pressed and change GO transform rotation. 2 Answers