Hi first of all excuse my English in not American
Ok so heres the deal Im trying to make a open world driving game but I have encountered a problem if the car trips and lands on its back theres no way of getting it back to the right position.
I have googled my answer and got nothing but scripts that dont work
All I need is it to rotate 180 degrees on trigger.
Thanks for your time
Anyways I include my code so it helps.
#pragma strict
var forwardSpeed : float = 3.0;
var turnspeed : float = 2.0;
function Update ()
{
// This is the forward speed
var forwardMoveAmount = Input.GetAxis("Vertical") *forwardSpeed;
//this rotation speed
var turnMoveAmount = Input.GetAxis("Horizontal") * turnspeed;
//rotation
transform.Rotate(0,turnMoveAmount,0);
//moving by applying force
rigidbody.AddRelativeForce(0,0,forwardMoveAmount);
}
Just grab the original euler angles on start or awake, if the user hits the key you wish to assign for this action, have it rotate back to the original angle on z axis.
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour
{
Vector3 reset;
Vector3 currentAngle;
void Start()
{
reset = transform.localEulerAngles;
currentAngle = transform.localEulerAngles;
}
void Update()
{
if(Input.GetKeyDown (KeyCode.E))
{
currentAngle.z = reset.z;
transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, transform.localEulerAngles.y, currentAngle.z);
}
}
}