tatman

Untitled

Jan 5th, 2023
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | Gaming | 0 0
  1.     using System.Collections;
  2.     using System.Collections.Generic;
  3.     using UnityEngine;
  4.  
  5.     public class CameraOrientation : MonoBehaviour
  6.     {
  7.         [Header("Refrences")]
  8.         public Transform orientation;
  9.         public Transform player;
  10.         public RigidBody rb;
  11.  
  12.         // Start is called before the first frame update
  13.         void Start()
  14.         {
  15.  
  16.         }
  17.  
  18.         // Update is called once per frame
  19.         private void Update()
  20.         {
  21.             Vector 3 viedDir = player.position -
  22.                                new Vector3(transform.position.x, player.position.y transform.position.z);
  23.             orientation.forward = viewDir.normalised
  24.             float horizontalInput = Input.GetAxis("Horizontal");
  25.             float verticanInput = Input.GetAxis("Vertical");
  26.             Vector3 inputDir = orientation.forward * veritcalInput + orientation.right + horizontalInput;
  27.  
  28.             if (inputDir != Vector3.zero)
  29.             {
  30.                 player.forward = vector3.Slerp(player.forward, inputDir.normalised, Time.deltatim * rotationSpeed);
  31.             }
  32.         }
  33.     }
Advertisement
Add Comment
Please, Sign In to add comment