- Home /
Question by
Jammer3000 · Aug 22, 2014 at 09:38 PM ·
javascriptmovementsmooth
Move Object Smoothly
I want this the objects in my array to move from one point to another point smoothly. I have tried a bunch of stuff and can't seem to get this to work. The code I am using now is below and also the error I am getting when I try this?
Code
var spikeLeftArray : GameObject[];
var spikeLeftClonesArray : GameObject[];
function Start ()
{
for (var j : int = 0; j < 3; j++)
{
spikeLeftClonesArray[j] = Instantiate(spikeLeftArray[j], Vector3(0, Random.Range(-3, 3), 0), Quaternion.identity);
}
}
function OnCollisionEnter2D (col: Collision2D)
{
if (col.gameObject.tag == "RightWall")
{
for (var j : int = 0; j < spikeLeftClonesArray.Length; j++)
{
spikeLeftClonesArray[j].transform.position = transform.position = Vector3.Lerp(3, transform.position, transform.position);
}
}
}
Error
BCE0017: The best overload for the method 'UnityEngine.Vector3.Lerp(UnityEngine.Vector3, UnityEngine.Vector3, float)' is not compatible with the argument list '(int, UnityEngine.Vector3, UnityEngine.Vector3)'.
Comment
As you are aware your line 19 is the problem http://docs.unity3d.com/ScriptReference/Vector3.Lerp.html should help you!!
Best Answer
Answer by NeverEndingPrjct · Aug 24, 2014 at 09:47 PM
spikeLeftClonesArray[j].transform.position = transform.position = Vector3.Lerp(3, transform.position, transform.position);
U have to lerp in the updatemethod ... so use an bool and if dat bool is true u lerp the position
You are right the Lerp must be done in the Update or FixedUpdate function!