- Home /
Smooth movement for Gameobjects switching position
I'm working on a game and one of the main mechanics is switching around the different colored cannons using your finger. I got this mechanic to work so when you drag cannons over each other, they switch positions. Right now it is very "poppy" and instant because it's just setting positions, so that makes sense, but one thing is I want it to be smooth when the cannons switch positions. I tried using Vector.lerp but it doesn't seem to be working the way I intended. This question is continuing from this one. Here's the code I'm using to set the position of a cannon and the attempted use of lerp.
gameObject.transform.position = Vector3.Lerp(gameObject.transform.position, new Vector3(0.21f, -4.11f, 0.51f), lerpSpeed);
Answer by freemann098 · Jan 30, 2016 at 09:27 PM
I wasn't using lerp correctly. I got it to work.
Answer by CommunistKitten · Oct 15, 2015 at 01:12 AM
@freemann098 You should be able to just use Vector3.MoveTowards http://docs.unity3d.com/ScriptReference/Vector3.MoveTowards.html
What is not working? Are the cannons not moving, or are they moving to the wrong positions?
It's just working the same as it was before.
Your answer
Follow this Question
Related Questions
Vector3.distance is always returning 0 4 Answers
How to Clamp LookAt on the Y Axis 1 Answer
Rotating game object to movement direction 1 Answer