dronkowitz

PlayerMovement.cs (Sonic Adventure 2 Battle)

Sep 27th, 2021 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerMovement : MonoBehaviour
  6. {
  7.     // Public Variables
  8.     public Transform liveCam;
  9.     public Camera mainCamera;
  10.     public Rigidbody body;
  11.     public Vector2 pInput;
  12.     public Vector3 mov;
  13.     public float speed = 5.0f;
  14.     // Start is called before the first frame update
  15.     void Start()
  16.     {
  17.  
  18.     }
  19.  
  20.     // Update is called once per frame
  21.     void Update()
  22.     {
  23.  
  24.     }
  25.     private void FixedUpdate()
  26.     {
  27.         CharacterMovement(PlayerInput());
  28.     }
  29.     Vector2 PlayerInput()
  30.     {
  31.         // Inputs for Movement
  32.         float h = Input.GetAxis("Horizontal");
  33.         float v = Input.GetAxis("Vertical");
  34.         pInput = new Vector2(h, v);
  35.  
  36.  
  37.         return pInput;
  38.     }
  39.     // Rotates Lead Character
  40.     public void RotateLeader(Vector3 dir)
  41.     {
  42.         if (dir != Vector3.zero)
  43.         {
  44.             dir = new Vector3(dir.x, 0, dir.z);
  45.             transform.rotation = Quaternion.LookRotation(dir);
  46.  
  47.         }
  48.     }
  49.     public void CharacterMovement(Vector2 pInput)
  50.     {
  51.         // Camera Movements and Rotations
  52.         float rotx = Input.GetAxis("Mouse X");
  53.         float roty = Input.GetAxis("Mouse Y");
  54.         transform.Rotate(transform.up * rotx);
  55.         transform.Rotate(transform.right * roty);
  56.  
  57.         // Basic Player Movements
  58.         mov = liveCam.forward * pInput.y + liveCam.right * pInput.x;
  59.         mov = liveCam.up * pInput.y + liveCam.up * pInput.y;
  60.         body.AddForce(mov * speed);
  61.     }
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment