update lại về cam và logic

This commit is contained in:
2026-05-04 14:52:40 +07:00
parent 5bc99cd1b6
commit 24866c6c99
14 changed files with 460 additions and 43 deletions

View File

@@ -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);
}
}
}