- Home /
Move an object on collision
Hey guys need some help...
Currently I have this script applied to a wall so that when the player collides with said wall they are destroyed
function OnCollisionEnter(theCollision : Collision){
if(theCollision.gameObject.name == "Player"){
Destroy(gameObject.Find("Player"));
}
}
How would I go about making this script move the player to a certain position e.g the start instead of destroying the object.
Any help would be much appreciated as I'm a complete noob :D
Answer by LegionIsTaken · Oct 11, 2011 at 12:36 PM
Use:
transform.position = Vector3(x,y,z);
To set the position of the object.
Ok that kinda worked except its moving the walls to the set position and not the player. How do I get it to move the player ins$$anonymous$$d?
$$anonymous$$y script looked like this now
function OnCollisionEnter(theCollision : Collision){ if(theCollision.gameObject.name == "Player"){ transform.position = Vector3(2.227529,22.1897,-23.69337); } }
I'm guessing I have to find the "Player" object some how but I'm not sure how. Sorry for being a noob :D
To find the player you can use GameObject.Find("Player").transform.position = whatever