Advertisement
LeeMace

Move Vehicle Forward

Dec 15th, 2022
39
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.62 KB | Gaming | 0 0
  1. using UnityEngine;
  2.  
  3. public class PlayerController : MonoBehaviour
  4. {
  5.  
  6. [SerializeField] float horsePower = 0f;
  7.  private float turnSpeed = 35.0f;
  8.     private float horizontalInput;
  9.     private float forwardInput;
  10.    
  11.   private Rigidbody playerRb;
  12.  
  13.    private void Start()
  14.     {
  15.         playerRb = GetComponent<Rigidbody>();
  16.     }
  17.     void FixedUpdate()
  18.     {
  19.   //Move the vehicle forward
  20.         playerRb.AddRelativeForce(Vector3.forward * forwardInput * horsePower);
  21.         //have vehicle rotate as it turns
  22.         transform.Rotate(Vector3.up * Time.deltaTime * turnSpeed * horizontalInput);
  23.     }  
  24. }    
Advertisement
Comments
  • LeeMace
    1 year
    # C# 0.11 KB | 0 0
    1. An annoying way to move the vehicle forward as I have to mess with the centre of mass position and horse power
Add Comment
Please, Sign In to add comment
Advertisement