- Home /
Question by
Wolfdog · Jul 08, 2015 at 07:31 PM ·
scripting problemlerpsmooth
Smoothly moving object along 1 axis
I have 2 gameobjects: obj1
and obj2
I control obj2 along the x axis manually. I want obj2's y position to slowly match obj1's y position. I can't use Vector3 Lerp, as I control obj2's x movement. I only want to lerp the y axis.
How do I do this?
My attempt:
obj2.transform.position = new Vector3 (obj2.transform.position.x + myManualInput, obj1.transform.position.y, 0);
This however, instantly jumps to obj1's y position. I want it to move smoothly.
Comment
Best Answer
Answer by $$anonymous$$ · Jul 08, 2015 at 07:49 PM
Attach this script to Obj2 and when you move Obj1 along the Y axis, Obj2 will follow
public Transform Obj1;
private void Update()
{
Vector3 NewPos = new Vector3(this.transform.position.x, Obj1.position.y, 0);
this.transform.position = Vector3.Lerp(transform.position, NewPos, Time.deltaTime);
}
Your answer
Follow this Question
Related Questions
Move A Camera Between Two Points Smoothly 1 Answer
How to move an object from point A to point B with one key press 3 Answers
Smoothing motion with vector3 lerp 3 Answers
interpolate a move variable 0 Answers
Smoothly stop rotating 1 Answer