- Home /
Car won't return to respawn point after hitting a trigger
I am making a simple car game and want the car to reset to a respawn point if the user hits a wall. Using the UnityStandardAssets FPS or 3rd person controllers, the respawn script works fine, but not with the car model I am trying to use or the UnityStandardAssets-Vehicles Car. The wall has 'convex' and 'isTrigger' checked, and has the respawn script applied. The car has a rigidbody on the main node, as well as a box collider in the general shape of the car.
Here is the respawn script:
using UnityEngine;
using System.Collections;
public class RespawnScript : MonoBehaviour {
//Place holder for the spawn point
public Transform respawnPoint;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
//This fires off when the player hits the wall
void OnTriggerEnter(Collider other)
{
print("Wall Hit");
//Moves the player to the spawn point
other.gameObject.transform.position = respawnPoint.position;
}
}
I see the 'Wall Hit' message printed when the car drives into the wall, so I know the car and wall are communicating. I just can't get the script to properly respawn the car. If anyone has any easier solutions, I would gladly try them.
How are you moving your car I mean using rigidbody or using transform. If you are using rigidbody to move your car script works fine.
Answer by m2graphics · May 13, 2015 at 07:42 PM
I was able to solve this by adding public GameObject Player;
to the beginning of the script, and then replacing other.gameObject.transform.position
with player.transform.position.
Answer by alok-kr-029 · May 11, 2015 at 06:22 AM
Your problem is not very clear ,what I am understanding is you are having problem respwaning the car although the your trigger is working fine and "wall hit" get printed .
in place of position try using localPosition. hope it might work .
Your answer
Follow this Question
Related Questions
Guides or Tutorials for a Very Basic Enemy AI? [Unity 5] 1 Answer
Multiplayer Respawning Problems 0 Answers
EventTrigger PointerEnter 1 Answer
Car trembling when reaching a certain speed 1 Answer
Multiplayer Respawning Problems 0 Answers