Resetting rotation of FPSController on collision.
I'm creating a 3d platformer in which the player can fall off the side and his position is reset to the latest checkpoint. I wish to reset the player's rotation at the same time, but have been wrestling with it for hours to no avail.
The script I'm using to reset the player is attached to a collision box underneath the level and goes something like this:
using UnityEngine; using System.Collections;
public class Setback : MonoBehaviour {
string TheCollider;
Transform SpawnPoint, Player;
void Start () {
SpawnPoint = GameObject.Find("SpawnPoint1").transform;
Player = GameObject.Find("FPSController").transform;
}
void OnTriggerEnter (Collider other) {
TheCollider = other.tag;
if (TheCollider == "Player") {
Player.transform.position = SpawnPoint.transform.position;
}
}
}
How do I reset the rotation of the player inside this script? Or do I have to create a new script and attach it to the player?
Many thanks in advance.
Save your rotation the first time you spawn (in void Start() perhaps) to a Quaternion originalRotation. Then use transform.rotation = Quaternion.lookRotation(originalRotation); I think this would do the job.
Your answer
Follow this Question
Related Questions
Rotation Troubles 0 Answers
Rotation resets on character controller 0 Answers
Reset rotation of gameobject 1 Answer
top down 2D : bad enemy shooting angle 0 Answers
How to modify this script to not rotate the camera when I rotate the player. 1 Answer