- Home /
Question by
ibayibay1 · Feb 16, 2013 at 04:26 AM ·
collidervector3.lerppushing
push the player back?
i have some fans. I want it so when the player enters a sphere collider. they push the player back. but what i would really like is for the player to enter collider. player gets teleported to point A. and then Vector3.Lerped to point B smoothly. how could i go about doing this?
Comment
Answer by Paulo-Henrique025 · Feb 16, 2013 at 06:27 AM
When enter the trigger set the position of the player to A and them lerp to B, you pretty much said it all.
PseudoCode:
Vector3 pointB;
bool canLerp = false;
void Update()
{
if(canLerp)
{
player.transform.position = Vector3.Lerp(player.transform.position, pointB, Time.deltaTime *5);
}
}
void OnTriggerEnter(Collider col)
{
if(col.gameObject.tag == "fan")
{
player.transform.position = col.GetComponent<FanScript>().playerPointA;
pointB = col.GetComponent<FanScript>().playerPointB;
canLerp = true;
}
}
You must also check to see if the player has arrived at point be to set canLerp to false again. And you can also use iTween to do this kind of stuff the easy way.