Diamond32_Tutoriales

ThirdPerson

Mar 7th, 2021
660
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class ThirdPerson : MonoBehaviour
  6. {
  7.     public CharacterController controler;
  8.  
  9.     public float Speed = 6f;
  10.     public float TurnSmoothTime = 0.3f;
  11.     float turnSmoothvelocity;
  12.  
  13.     public Transform camera;
  14.     Animator anim;
  15.     bool IsWalking;
  16.  
  17.  
  18.      void Start()
  19.     {
  20.         anim = GetComponent <Animator>();
  21.     }
  22.  
  23.      void Update()
  24.     {
  25.         float xW = Input.GetAxisRaw("Horizontal")/** Speed * Time.deltaTime*/;
  26.         float yW = Input.GetAxisRaw("Vertical") /** Speed * Time.deltaTime*/;
  27.  
  28.         Vector3 direction = new Vector3 (xW, 0f, yW).normalized;
  29.        
  30.         if (direction.magnitude >= 0.01f)
  31.         {
  32.             float TargetAngle = Mathf.Atan2 (direction.x, direction.z) * Mathf.Rad2Deg + camera.eulerAngles.y;
  33.  
  34.             float angle = Mathf.SmoothDampAngle (transform.eulerAngles.y, TargetAngle, ref turnSmoothvelocity, TurnSmoothTime);
  35.             this.transform.rotation = Quaternion.Euler (0f, angle, 0f);
  36.  
  37.             Vector3 moveDirection = Quaternion.Euler (0, TargetAngle, 0) * Vector3.forward + Vector3.down;
  38.  
  39.             controler.Move(moveDirection.normalized * Speed * Time.deltaTime);
  40.             anim.SetBool("Walk", false);
  41.             anim.SetBool("Walk", true);
  42.             IsWalking = true;
  43.         }
  44.         else
  45.         {
  46.             IsWalking = false;
  47.             anim.SetBool("Walk", true);
  48.             anim.SetBool("Walk", false);
  49.             Vector3 moveDirection = Vector3.down;
  50.  
  51.             controler.Move(moveDirection.normalized * Speed * Time.deltaTime);
  52.         }
  53.  
  54.         if (Input.GetKey (KeyCode.LeftShift))
  55.         {
  56.  
  57.         }
  58.     }
  59. }
  60.  
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×