- Home /
Rotate Rigid body simple car controlls
hey gang just wondering how to rotate a car using Ridgidbody, I tried using transform, but the car rotated while driving forward rather thern turning.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
public float Speed = 0;
public float TurnSpeed = 20;
public float AccelerateSpeed = 10;
public float TopSpeed = 500;
public float BoostSpeed = 650;
public float DeathSpeed = 300;
public float LeftEngineHealth;
public float RightEngineHealth;
public Rigidbody rb;
public GameObject Explosion;
public GameObject ExngineEffect;
// Update is called once per frame
void Update () {
if (Input.GetButton("Fire1")) {
ExngineEffect.SetActive (true);
if (Speed < TopSpeed) {
Speed += AccelerateSpeed;
}
rb.velocity = new Vector3 (0, 0, Speed);
}
if (Input.GetButtonUp("Fire1")) {
ExngineEffect.SetActive (false);
if (Speed > 0) {
Speed -= 30;
}
rb.velocity = new Vector3 (0, 0, Speed);
}
if (Input.GetButton("Left")) {
// Turn Left
}
if (Input.GetButton ("Right")) {
// Turn Right
}
}
void OnTriggerEnter (Collider Other){
if (Other.gameObject.tag == "Obsticle") {
if (Speed > DeathSpeed) {
DeathTrigger();
}
}
}
void DeathTrigger(){
//kill player
}
}
Comment
Answer by Bleakmountain50 · May 14, 2018 at 01:20 PM
Should be something along the lines of gameObject.GetComponent(Velocity.up * NUMBER);