How to use Lerp with OnTriggerEnter

Im a bit of a Noob at Unity, I’ve only got 4 weeks of experience, and Im testing out what I learned already. Im trying to get an object to lerp on contact, but I have no idea what to do. Here is my code so far
using UnityEngine;
using System.Collections;

public class PortalizerCS : MonoBehaviour
{
	public float move = 2;

	private Vector3 newPosition;

	void Awake ()
	{
		newPosition = Transform.position;
	}

	void Update ()
	{
		PositionChanging();
	}

	void PositionChanging ()
	{
		Vector3 positionA = new Vector3 (704, 4.3, 986);
	//this is where Im confused. It's supposed to be an if statement, but for OnTriggerEnter, it has to be void :/
			newPosition = positionA;

		Transform.position = Vector3.Lerp(transform.position, newPosition, move * Time.deltaTime);

	}
}

If you want the object to lerp on contact(assuming you are using rigidbodies / colliders), you can move the Lerp code from Update() into OnCollisionEnter(). Right now it’s in the Update so it’s being called every frame.

something like:

void OnCollisionEnter(Collision collision) {
//Something made contact with me, lets lerp!
PositionChanging();
}

Just take a bool and use it to perform Lerp. Eg OnTriggerEnter(Collider other) is called when a body with isTrigger=true comes in contact with other.

What you have to do is

private bool isLerp=false;

void Update(){
   if(isLerp)
      PositionChanging();
}

void OnTriggerEnter(Collider other){
//Make Sure that your codes gets in here
      isLerp=true;
}

U will have to tweek it according to you needs. But for now it will work fine.

I hope this help you out. :slight_smile: