Question by
willbot · Sep 24, 2019 at 12:43 PM ·
cameraquaternioncamera-movementlookatpokemon
Buggy "Floor Drag" Camera
I'm attempting to implement a camera system similar to the Pokémon Go map, where a player taps the floor and "drags" it around a central point.
I have an empty GameObject centered to the player and a camera as a child. I'm Ray Tracing a touch from LateUpdate and passing a world coordinate to a script that uses a LookAt to point the object in the right direction. It's not working at all and I can't work out why. Could this be to do with Gimbal Lock?
Really stuck on this one.
public void BeginDragCamera(Vector3 _worldPosition)
{
DebugPointer.transform.position = _worldPosition;
beginDragRotOffset = transform.rotation.eulerAngles.y + Quaternion.LookRotation(_worldPosition).eulerAngles.y;
beginDragRotOffset %= 360;
Mathf.Abs(beginDragRotOffset);
Debug.Log("Inital camera rotation offset: " + beginDragRotOffset + " degrees.");
}
public void DragCamera(Vector3 _worldPosition)
{
float _targetRotation = Quaternion.LookRotation(_worldPosition).eulerAngles.y + beginDragRotOffset;
_targetRotation %= 360;
Mathf.Abs(_targetRotation);
transform.eulerAngles = new Vector3(0, -_targetRotation, 0);
Debug.Log("_targetRotation: "+_targetRotation);
autoCamera = false;
}
Comment