2022-03-03 07:29:00 +01:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class TestMovement : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public CharacterController controller;
|
2022-03-03 16:00:02 +01:00
|
|
|
//public Transform gameobject;
|
2022-03-03 07:29:00 +01:00
|
|
|
|
|
|
|
|
public float speed = 15f;
|
|
|
|
|
public float turnSmoothness = 0.1f;
|
2022-03-03 16:00:02 +01:00
|
|
|
public float targetAngle, angle;
|
2022-03-03 07:29:00 +01:00
|
|
|
float turnSmoothVelocity;
|
|
|
|
|
float x, y;
|
2022-03-03 16:00:02 +01:00
|
|
|
public Vector3 direction;
|
2022-03-03 07:29:00 +01:00
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
x = Input.GetAxisRaw("Horizontal");
|
|
|
|
|
y = Input.GetAxisRaw("Vertical");
|
|
|
|
|
direction = new Vector3(x, 0f, y).normalized;
|
|
|
|
|
|
|
|
|
|
if (direction.magnitude >= 0.1f) {
|
2022-03-03 16:00:02 +01:00
|
|
|
targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg; //+ gameobject.eulerAngles.y
|
|
|
|
|
angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnSmoothness);
|
2022-03-03 07:29:00 +01:00
|
|
|
transform.rotation = Quaternion.Euler(-90f, angle, 0f);
|
|
|
|
|
|
2022-03-03 16:00:02 +01:00
|
|
|
//Vector3 moveDir = Quaternion.Euler(0f, targetAngle, 0f) * Vector3.forward;
|
2022-03-03 07:29:00 +01:00
|
|
|
controller.Move(direction * speed * Time.deltaTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|