How to set limitations on rotateAround in C#?
So here's the long and short of it. I managed to get the camera to rotate around something. However, I want to set boundaries on how far it can go left or right. The problem, however, is that it seems to have nothing that will actually be able to measure how far it goes around the object. I know I could likely set restrictions on the x,y, and z of the position and the y of the rotation (Those are the 4 things it seems to change when I rotate it) but I don't know how to access, much less put restrictions on those either. Here's the working code for the rotation:
public class RotateCam : MonoBehaviour { public static bool GreaterThen; public static bool LessThen; void Start(){ GreaterThen = false; LessThen = false; } void Update () { if (GreaterThen == false) { if (Input.GetKeyDown (KeyCode.LeftArrow)) { transform.RotateAround (Vector3.zero, Vector3.up, 300 * Time.deltaTime); } } if(LessThen == false){ if (Input.GetKeyDown (KeyCode.RightArrow)) { transform.RotateAround (Vector3.zero, Vector3.down, 300 * Time.deltaTime * 2); } } } }
Don't mind the bools, they were a failed attempt at what I need help with.
please help.
I'm just writing this as a comment to fix the formatting on the code he posted.
public class RotateCam : $$anonymous$$onoBehaviour {
public static bool greaterThan;
public static bool lessThan;
void Start(){
greaterThan = false;
lessThan = false;
}
void Update () {
if (!greaterThan) {
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.LeftArrow)) {
transform.RotateAround(Vector3.zero, Vector3.up, 300 * Time.deltaTime);
}
}
if(!lessThan){
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.RightArrow)) {
transform.RotateAround(Vector3.zero, Vector3.down, 300 * Time.deltaTime * 2);
}
}
}
}
Answer by LeonardNS · Oct 08, 2018 at 11:44 AM
I couldn't get the image to work in comments. You could use the direction where the target object is facing as a reference for when you can rotate or not.
Your answer
Follow this Question
Related Questions
Undesired Angles with transform.Rotate(...) 0 Answers
Cant stop object/ridgidbody from rotating 2 Answers
Rotate object with 90 degrees? 1 Answer
Rotate player with mouse. 0 Answers