AlphaPenguino

PlayerController

Feb 11th, 2025
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | Source Code | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerController : MonoBehaviour
  6. {
  7.     // Start is called before the first frame update
  8.     void Start()
  9.     {
  10.  
  11.     }
  12.  
  13.     // Update is called once per frame
  14.     public float speed = 20;
  15.     public float turnSpeed;
  16.     public float turnInput;
  17.     public float turnForward;
  18.     void Update()
  19.     {
  20.         turnInput = Input.GetAxis("Horizontal");
  21.         turnForward = Input.GetAxis("Vertical");
  22.         transform.Translate(Vector3.forward * Time.deltaTime * speed * turnForward);
  23.        
  24.         // Only rotate if moving forward or backward
  25.         if (turnForward != 0)
  26.         {
  27.             transform.Rotate(Vector3.up, turnSpeed * turnInput * Time.deltaTime);
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment