- Home /
 
How to make a cube (go to a certain position) after colliding with a plane?
i recently got unity 3D and i have started making a game consisting of 2 cubes trying to knock each other off the arena. i am having some trouble with making the cube detect collision with the plane underneath the arena which i want it to make the cube re spawn when ever it touches it. i have done this so far:
 using UnityEngine;
 using System.Collections;
 
 public class plz : MonoBehaviour
     {
         void OnCollisionEnter(Collision col)
         {
             if (col.gameObject.name == "Death")
             {
                 transform.localposition = new Vector3 (10.56507f, -13.15086f, 9.080673f);
             }
         }
     }
 
               PLEASE HELP!!
What exactly isn't working? Also, please place the code in correct formatting.
Answer by bubzy · Oct 30, 2016 at 08:35 AM
edited the answer to format the code correctly, in future use the "101010" button, it makes it easier to read :)
why not just check the current height of the cube?
 public Vector3 spawnPos = new Vector3(10,1,9);
 public float deathHeight = -13f;
 public int lives = 3; 
 //these are all public so that you can change them in the editor
 
 void Update()
 {
 if(transform.position.y < deathHeight)
 {
 lives --; //lose a life
 transform.position = spawnPos; //move the object back to the spawn position
 }
 
 
               hope this helps in some way :)
Your answer
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Collision Not Working 1 Answer
OnTriggerEnter called much less often after a player respawn? 1 Answer
Not detecting collision? 1 Answer