Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class ThirdPerson : MonoBehaviour
- {
- public CharacterController controler;
- public float Speed = 6f;
- public float TurnSmoothTime = 0.3f;
- float turnSmoothvelocity;
- public Transform camera;
- Animator anim;
- bool IsWalking;
- void Start()
- {
- anim = GetComponent <Animator>();
- }
- void Update()
- {
- float xW = Input.GetAxisRaw("Horizontal")/** Speed * Time.deltaTime*/;
- float yW = Input.GetAxisRaw("Vertical") /** Speed * Time.deltaTime*/;
- Vector3 direction = new Vector3 (xW, 0f, yW).normalized;
- if (direction.magnitude >= 0.01f)
- {
- float TargetAngle = Mathf.Atan2 (direction.x, direction.z) * Mathf.Rad2Deg + camera.eulerAngles.y;
- float angle = Mathf.SmoothDampAngle (transform.eulerAngles.y, TargetAngle, ref turnSmoothvelocity, TurnSmoothTime);
- this.transform.rotation = Quaternion.Euler (0f, angle, 0f);
- Vector3 moveDirection = Quaternion.Euler (0, TargetAngle, 0) * Vector3.forward + Vector3.down;
- controler.Move(moveDirection.normalized * Speed * Time.deltaTime);
- anim.SetBool("Walk", false);
- anim.SetBool("Walk", true);
- IsWalking = true;
- }
- else
- {
- IsWalking = false;
- anim.SetBool("Walk", true);
- anim.SetBool("Walk", false);
- Vector3 moveDirection = Vector3.down;
- controler.Move(moveDirection.normalized * Speed * Time.deltaTime);
- }
- if (Input.GetKey (KeyCode.LeftShift))
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement