https://www.reddit.com/r/unrealengine/comments/s8k7m3/just_started_prototyping_a_first_person_twist_on/
I want to make the camera look at the monitor when it is clicked, as shown in the video. I’m trying to implement this using DoTween, but I’m not sure how to do it. Could you please help me?
#How can I use DOTween in Unity to make the camera focus on an object when it is clicked?
13 messages · Page 1 of 1 (latest)
{
public Transform cameraTransform; // 카메라의 Transform
public Transform cubeTransform; // 큐브의 Transform
public float duration = 1f; // 이동에 걸리는 시간
private void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
GetComponent<FirstPersonLook>().enabled = false;
Vector3 targetPosition = cubeTransform.position + new Vector3(-2, 0, 0); // 거리 및 높이 조절
cameraTransform.DOMove(targetPosition, duration);
}
if (Input.GetKeyDown(KeyCode.S))
{
GetComponent<FirstPersonLook>().enabled = true;
// Player의 상대적 좌표를 기준으로 카메라 이동
cameraTransform.DOLocalMove(new Vector3(0, 1.5f,0 ), duration);
}
}
}
I want to change the camera angle to face the front of the cube.
so for me if i would do it , i will simply make a spotlight with 0 intensity so its not a light anymore but i will use its gizmo to know which angle my object is looking at , after that i will make a reference for its transform , and then i will use dotween to move position and rotation of my camera to the rotation and rotation of the Fake Spotlight
@novel orchid
Thank you, I was able to solve the problem thanks to your help. However, did I write the code incorrectly? When I watch the video, I notice two issues: first, when the camera returns to the player, the angle doesn't move smoothly, and second, if the camera switches while moving, the camera's movement becomes strange
using UnityEngine;
public class CameraMove : MonoBehaviour
{
public FirstPersonMovement FirstPersonMovement;
public Transform cameraTransform; // 카메라의 Transform
public Transform cubeTransform; // 큐브의 Transform
public float duration = 1f; // 이동에 걸리는 시간
private Vector3 originalPosition;
private Quaternion originalRotation;
private void Start()
{
originalPosition = cameraTransform.localPosition;
originalRotation = cameraTransform.localRotation;
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.E))
{
FirstPersonMovement.enabled = false;
GetComponent<FirstPersonLook>().enabled = false;
Cursor.lockState = CursorLockMode.None;
cameraTransform.DOMove(cubeTransform.position, duration);
cameraTransform.DORotateQuaternion(cubeTransform.rotation, duration);
}
if (Input.GetKeyDown(KeyCode.R))
{
FirstPersonMovement.enabled = true;
GetComponent<FirstPersonLook>().enabled = true;
Cursor.lockState = CursorLockMode.Locked;
cameraTransform.DOLocalMove(originalPosition, duration);
cameraTransform.DOLocalRotateQuaternion(originalRotation, duration);
}
}
}
@zealous fjord
i would suggest to make the camera not a child of the player and make it follow the player and unfollow when it zoom
I've tried it, but there are too many bugs. Would it be better to use Cinemachine instead?