- Home /
how to move the player away when it's hit
Hello, i'm trying to make a tank game. and it just won't work for the player to die. I wanted to test it by tagging the enemy projectile. but the projectile disappears when it collided to the tank and a huge explosion came.. but i didn't "die" are there any other ways to do this?? here is my code
private var dead = false;
function OnControllerColliderHit(hit : ControllerColliderHit) { if(hit.gameObject.tag == "rocket") { dead = true; }
}
function LateUpdate() { if(dead) {
transform.position = Vector3(100,100,100); dead = false; } }
Answer by Berenger · Dec 22, 2010 at 03:54 PM
If your player die, you have to think of what's going to happen next. Is it going to respawn elsewhere, or displaying a game over splash screen ? The destruction seems unlikely, you don't need it either way.
What happen if you do a Debug.Log( hit.gameObject.tag ); in OnControllerColliderHit? Anyway for your tests, I'm not sure playing with your player transformation is a good idea, better to do a CharacterController.Move or something like that.
I wanted to check if something happens when the projectile collides with my tank. And i checked it by setting the die to move to another place. so i knew ok. so something is happening. then i could think about what i want to do with it. But here is the Problem: Nothing happens when they collide with each other,
so i want to know. is there any other way for my player to die.
Answer by JGeorge · Dec 22, 2010 at 03:19 PM
What do you mean by die? Do you want the tank object to be destroyed, etc. We need more information to help you.
Answer by Bram 1 · Dec 22, 2010 at 03:21 PM
yes i want the tank to be destroyed. but the tank is the player.. i control it what do you need to know more ?
the moving to 100, 100, 100 was just to test if the script worked correctly
is there a way to destroy it when it hit a explosion ?
if you're gonna say something like this, in the future, just add a comment under the answer to tell them something. only answer if you know tha answer.
I have the same problem. In previous versions of unity work perfectly. These transform. position = new Vector3(0,0,0); But now if put this code in to the player collision detection it not working.