- Home /
Question by
faheemmoolla · Oct 21, 2018 at 12:59 PM ·
cameracamera rotaterotatearound
Clamping position of camera when using RotateAround?
Im making a game where the player rotates a camera(child of a camera holder) around a planet. I need to be able to clamp the position (and rotation) of the camera at certain points in time. Im using a RotateAround function and I was wondering if someone could help me to be able to clamp this? My code is below:
private void RotateCamera(Vector3 dragStartPosition, Vector3 dragEndPosition)
{
//normalised for odd edges
dragEndPosition = dragEndPosition.normalized *planetRadius;
dragStartPosition = dragStartPosition.normalized * planetRadius;
// Cross Product
Vector3 cross = Vector3.Cross(dragEndPosition, dragStartPosition);
// Angle for rotation
float angle = Vector3.SignedAngle(dragEndPosition, dragStartPosition, cross);
//Causes Rotation of angle around the vector from Cross product
holderTransform.RotateAround(planet.transform.position , cross, angle);
EventHandler.instance.AddHiddenEvent(EventHandler.EventType.panCamera);
}
private static Vector3? GetMouseHit()
{
RaycastHit hit;
int layer_mask = LayerMask.GetMask("Planet"); //raycasting on the planet
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity, layer_mask))
{
return hit.point;
}
return null;
}
Comment
Your answer
Follow this Question
Related Questions
Clamp Camera Angle not Working 2 Answers
Based on touch rotate camera object 0 Answers
Limit Y Axis transform.RotateAround 1 Answer
How to rotate camera diagonally over players shoulder while still facing towards players direction 0 Answers
Getting a scrolling camera to orbit around a circular walkway, following the player? 1 Answer