- Home /
Move an object down a little, then up to a position
Hey,
I have a game object, that I want to move down a little, and then up to a specific position in t time.
Lets say my object is at P0 position (0, 22, 0), and has a speed of S0(-15).
Now, I want to modify it's speed variable, to decrease (it will be calculated based on a distance of an object, lets say it is 2 at the moment), and after that, I want to increase it to move the object up to P1 position smoothly (it is constant, (0, 26, 0)), and do all of this in t time (it will be calculated as well, lets say it is 0.75 seconds at the moment).
It should move in a path like in the diagramm below (so, we should smoothly decrease the speed value, then increase it, and smoothly stop).
My question is, what is a good way to do this? The object is moving by this line (so the object only moves only up and down):
thisTransform.position += Vector3.up * speed * Time.deltaTime;
A good way: Animation
A more dynamic way: 3d Bezier Curves
Don't try to do it procedurally
Answer by nsxdavid · Mar 25, 2013 at 05:06 AM
In addition to just using an Animation clip, you can also use an Animation Curve. This is one of the more powerful features of Unity that few people think to use.
Create a public member of type AnimationCurve. In the inspector you can edit that property with an interactive curve editor. In your code use the Evaluate() method on the curve member. Just pass in T.
In your case you might have a curve for the Y position and another for speed and just plug the evaluations into your maths.
Your answer
Follow this Question
Related Questions
How to move object from existing position to new position and change its animation? 1 Answer
move a gameobject to left/right while going up 1 Answer
Lerp a Object along X and Z axis only. 3 Answers
C# move y position of object not working 2 Answers
How Do I lerp a game object from positionA to positionB 1 Answer