- Home /
How do I get the world space up direction for RotateAround?
I have been searching for a while for answers, what I have is this:
private RaycastHit frontHit;
private void DoRaycast()
{
Physics.Raycast(Camera.main.transform.position, Camera.main.transform.TransformDirection(Vector3.forward), out frontHit, Mathf.Infinity, groundLayer_Mask.value);
}
private void HoldRotate()
{
if (Input.GetButton("RightClick"))
{
if (frontHit.point != null)
{
transform.RotateAround(frontHit.point, Vector3.up, Input.GetAxisRaw("Mouse X") * mouseHorizontalRotationSpeed * Time.deltaTime);
transform.RotateAround(frontHit.point, Vector3.left, Input.GetAxisRaw("Mouse Y") * mouseVerticalRotationSpeed * Time.deltaTime);
return;
}
}
}
It looks a bit confusing, but the gist of it is, this script belongs on a camera, it looks for the ground and using this I can rotate around that point on the ground.
The Y-Axis works perfectly, but the X-Axis can only work perfectly, when the camera is parallel to the ground.
That is because the Rotations are relative to the Object instead of the world.
With Rotate you could do something like
transform.Rotate(Vector3.up, Space.World);
But I need the same effect with RotateAround, which doesn't have that.
Everything I heared when researching was
Just use Vecture3.up
Just use Space.World
Just use transform.InverseTransformDirection(Vector3.up)
All don't work or aren't applicable.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Smooth Camera Rotation relative to World [SOLVED] 1 Answer
Rotatearaound a moving object 1 Answer