update lại về cam và logic
This commit is contained in:
23
Assets/Script/ARFirstPersonController.cs
Normal file
23
Assets/Script/ARFirstPersonController.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ARFirstPersonController : MonoBehaviour
|
||||
{
|
||||
public Transform player; // Kéo nhân vật vào đây
|
||||
public Transform imageTarget; // Kéo ImageTarget vào đây
|
||||
public Vector3 viewOffset = new Vector3(0, -1.6f, 0.5f); // Điều chỉnh để mắt nhân vật khớp với camera
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if (player == null || imageTarget == null) return;
|
||||
|
||||
// Ép vị trí của toàn bộ ImageTarget di chuyển sao cho Player luôn nằm ở vị trí Camera
|
||||
// Điều này tạo ra góc nhìn thứ nhất trong AR
|
||||
Vector3 targetPosition = Camera.main.transform.position + Camera.main.transform.TransformDirection(viewOffset);
|
||||
|
||||
// Di chuyển ImageTarget để bù trừ vị trí
|
||||
imageTarget.position = targetPosition;
|
||||
|
||||
// Xoay ImageTarget để hướng nhìn của nhân vật khớp với hướng điện thoại
|
||||
imageTarget.rotation = Quaternion.LookRotation(Camera.main.transform.forward);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user