Camera to start moving on collision of object.

Hi there,

I have my camera moving script, basically What I am trying to do, is on collision of the character on another object I need the following camera script to run, basically the camera to starts moving up.

var Speed = 1;

function Update ()

{	
	transform.Translate(Vector3(0,1,0) * Time.deltaTime);

}

Here is a script that I have been working on for OnCollisionEnter and I can’t get it to run. anyone have any suggestions? or recommend another way to approach this?

var Speed = 1;

var touched = new HashSet.<GameObject>();


function OnCollisionEnter(collision : Collision) {

    if (collision.gameObject.tag == ("Player")  touched.Add(collision.gameObject))
{
    
   	transform.Translate(Vector3(0,1,0) * Time.deltaTime);
        

    }

}

Thanks :slight_smile:

transform.Translate()

This is “teleporting” to a new location each frame, it doesn’t interact with the physic engine and therefore doesn’t create any collisions. If you want to use the in built physics collisions you need to move by applying forces to the rigidbody. Or you can use translate and check for collisions in your own scripts.

Plenty of examples of both methods around here…