- Home /
How do i repeat the Lerp movement?
I have a script that says when i hit pointA, lerp to pointB. It works great but when I go back to point A it wont repeat the lerp movement. Additionally, how would i set the Vector3 position to an actual gameobject, my pointA and pointB?
var pointA:Vector3;
var pointB:Vector3;
var time:float = 10.0;
var i:float = 0.0;
private var rate:float = 0.0;
var detector : ClimbDetectionScript;
var pointAobject : GameObject;
var pointBobject : GameObject;
function Update ()
{
MoveObject(this.transform, pointA, pointB, time);
}
function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float)
{
rate = 1.0/time;
if (i < 1.0)
if (detector.startSpot == true)
{
i += Time.deltaTime * rate;
thisTransform.position = Vector3.Lerp(startPos, endPos, i);
}
}
Answer by SubatomicHero · May 03, 2013 at 08:10 AM
Potential answer to your first question:
After the movement is done, maybe reassign i=0???
Can you re ask the second question please...I'm not quite understanding what your asking. You can get the Vector3 position of any gameobject in the scene as long as you have a reference to it.
Vector3 pointA = pointAObject.transform.position;
I've tried resetting i to 0. All it does it make my player fall through the floor, its weird.
Would i put that as a var? Im trying to make so i can place an object into the inspector on this script to use its vector3
Replies to your questions: 1). O$$anonymous$$ then, not sure what else to do without seeing your project in action. 2). Yes a public var that can be edited within the inspector.
With this i am attempting to make a climbing function on my game. Poimt A is the bottom of the wall , PointB is at the top. When i touch A, i want to smoothly go up to B. Currently when i hit A i move insidethe wall towards B, it doesnt move me on the y axis at all. After i have hit A once, and i have moved , i can longer repeat the movement when i hit A again.
Thank you
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Switching Cameras at runtime 1 Answer
A node in a childnode? 1 Answer
How to move an object from point A to point B with one key press 3 Answers