- Home /
Question by
RaisingDreams · Mar 19, 2017 at 06:29 PM ·
bugtransform.positionrotatearound
Rotate Around not working with move
I'm trying to make the camera rotate around the player with the movement of the mouse on the Y axis as it follows the player. To do this I am using the following code:
private Vector3 offset;
public Transform target;
private void Start()
{
offset = target.position - transform.position;
}
private void LateUpdate()
{
target.RotateAround(transform.position, Vector3.left, -Input.GetAxis("Mouse Y"));
target.position = transform.position + offset;
}
If I remove the command to follow the player, the camera rotates around it, but if the command is enabled it rotates around itself, not the player. How to fix it?
Comment
Best Answer
Answer by corpsinheretoo · Mar 19, 2017 at 07:10 PM
In the first line of LateUpdate you call RotateAround - which changes both the rotation and position of target. In the 2nd line you reset the position - effectively undoing that part of RotateAround - so all you have is the rotation. Try making your camera a child of the player in the hierarchy. Then it will automatically follow the player.