- Home /
How to have an object follow another object only on the y axis.
So heres the deal, I have seen multiple posts like this, but none of them are really what I need. I want an object to follow another object only on the y, I don't want it to teleport to that objects y axis, I want it to follow it with a speed and so that it is not always on the same y axis, but will attempt to follow the player on it.
Answer by robertbu · Nov 11, 2014 at 12:09 AM
Given a target transform and writing in Javascript/Unityscript, put this in Update():
transform.position.y = Mathf.Lerp(transform.position.y, target.position.y, speed * Time.deltaTime);
'speed' is a variable you define and initialized. Start with a value of 3.0.
Your answer
![](https://koobas.hobune.stream/wayback/20220613171212im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Restrict Y axis 0 Answers
Adjust Y smoothly regardless of object rotation 1 Answer
Won't Shoot if Y Rotation Value Is Negative 2 Answers
How to stop rotation in x and y axis??? 2 Answers
How do I stop Unity thinking I'm editing multiple objects? 0 Answers