Hi!
So I’m doing a Mario Kart game and I’ve run in to a bit of a problem. Sometimes when I crash into stuff i flip over. This is a problem since I can’t reset it. So I was wondering how to do that.
What I need is how to by pressing (in this case) “R”, get your “Kart” to ur standard rotation so u stand with ur feet on the ground, so to speak. And at the same time you need to reset the speed you have to 0 so you can’t “cheat” and avoid for instans like a Banana.
Current movement script
using UnityEngine;
using System.Collections;
public class Acceleration : MonoBehaviour {
//Starting Speed which is Standby
public float startSpeed = 0.0F;
//Top speed
public float topSpeed = 1.0F;
//Speed at this moment
public float currentSpeed = 0.0F;
//Acceleration/s
public float accelerationSpeed = 0.1F;
//Turing speed
public float rotSpeed;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetKey ("a"))
{
this.transform.Rotate(0,-this.rotSpeed,0);
}
if (Input.GetKey ("d"))
{
this.transform.Rotate(0,this.rotSpeed,0);
}
if(Input.GetKey("w")){
currentSpeed = currentSpeed + (accelerationSpeed * Time.deltaTime);
}
else
{
currentSpeed = currentSpeed - (deaccelerationSpeed * Time.deltaTime);
}
currentSpeed = Mathf.Clamp (currentSpeed, startSpeed, topSpeed);
transform.Translate (0, 0, currentSpeed);
}
}