update lại về cam và logic
This commit is contained in:
@@ -4,6 +4,7 @@ public class PlayerController : MonoBehaviour
|
||||
{
|
||||
public Joystick joystick; // Kéo Fixed Joystick ở Canvas vào đây
|
||||
public float moveSpeed = 2f;
|
||||
public Animator animator; // Kéo Animator của nhân vật vào đây
|
||||
|
||||
void Update()
|
||||
{
|
||||
@@ -19,12 +20,22 @@ public class PlayerController : MonoBehaviour
|
||||
|
||||
// Di chuyển object theo trục X và Z
|
||||
Vector3 direction = new Vector3(horizontal, 0, vertical).normalized;
|
||||
float currentSpeed = direction.magnitude * moveSpeed;
|
||||
|
||||
transform.Translate(direction * moveSpeed * Time.deltaTime, Space.World);
|
||||
|
||||
// (Tùy chọn) Xoay object theo hướng di chuyển
|
||||
// Xoay object mượt mà theo hướng di chuyển
|
||||
if (direction != Vector3.zero)
|
||||
{
|
||||
transform.forward = direction;
|
||||
Quaternion targetRotation = Quaternion.LookRotation(direction);
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 15f * Time.deltaTime);
|
||||
}
|
||||
|
||||
// Cập nhật Animator
|
||||
if (animator != null)
|
||||
{
|
||||
// Giả sử Animator có parameter "Speed" kiểu Float
|
||||
animator.SetFloat("Speed", currentSpeed);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user