- Home /
script help gameobject to playercar
i need the gameobject to be PlayerCar (which is the only object it should collide with)
public var explosionPrefab : Transform;
function OnCollisionEnter(collidedObject : Collision) {
if (collidedObject.gameObject.tag == "Finish") {
Destroy(collidedObject.gameObject);
}
}
im making a car game were the players car collides with the other cars and destroys then instantly. so i need someone to change the script so it the other cars ONLY get destroyed when collided with the players cqr
make sure the player's car is not tagged "Finish". If thats not the answer, please try to ask the question in a way that we know what your problem is.
What you are trying to do:
What is actually happening:
What you think is causing the problem:
Answer by punkorange · Jun 01, 2011 at 10:11 PM
When attached to an object, this script function should check collisions to see if they are "OtherPlayer"s or not, if so it will remove them.
public var explosionPrefab : Transform;
function OnCollisionEnter(col: Collision){ if (col.gameObject.tag == "OtherPlayer") { Destroy(col.GameObject); }
thanks i have 2 enemy cars and 1 player car. i apply it to the enemy car called "Computercar". i then changed the tag from "OtherPlayer" to "Player". i then aply the explosion.prefab. now i play it and it doesnt work then i hit the car but it works if the enemy car 1 hits enemy car 2. what went wrong?
i added the script to the player car and it worked thanks punkorange.