rotate with Atan

How i can rotate the gameObject with input and atan function?

public class Move : MonoBehaviour {

    // Use this for initialization
    float angle = 0f;
    void Start () {
       
    }
   
    // Update is called once per frame
    void Update () {
        float r = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");


        if (r != 0)
        {
            float angle = Mathf.Atan(r) * Mathf.Rad2Deg;
            float clamp = Mathf.Clamp(this.transform.rotation.y, -angle, angle);
            this.transform.rotation = Quaternion.AngleAxis(clamp, Vector3.up);
            //this.transform.position += new Vector3(r*Time.deltaTime, 0, 0);
        }

       
    }
}

I haven’t on clue on that specifically. I know I’ve used atan2 for rotating 2d objects, in the past.

Perhaps if you talk about what you’re after, people could offer suggestions. Unless, of course, you have to do it that way (?), in which case, I’ll just let someone else answer :slight_smile:

Hi, I’m not sure what do you mean, but usually Atan and Atan2 uses for get angle between two points.

float angletotarget=Mathf.Atan2(targetx, targety) * Mathf.Rad2Deg;

If you want to rotate object in degrees you can do that by Euler method.

this.transform.rotation=Quaternion.Euler(anglex, angley, anglez);

“How do I use a sledgehammer to hang a door?”

This question would only make sense if all you had was a sledgehammer and you needed to figure out how to hang a door using only a sledgehammer.

Is there some reason you’re restricted to just atan?

Or are you just assuming you need atan?

If you’re just assuming you need it… well, you don’t know how to do it, so why make that assumption? Instead how about you ask “How do I hang a door?” or rather “How do I rotate an object based on the inputs from a user?” And then go into detail of what outcome you expect, rather than stabbing at the possible functions/tools you’d use to accomplish it.

There’s not a lot we can do to help if you don’t tell us what you want to accomplish.

Atan & Atan2 are Inverse Trigonometry functions for calculating angles from slope - so probably not quite what you want here. Perhaps this is what you’re after?

float clampedAngle = 90f;
float angle = r * (2f * Mathf.PI * Mathf.Rad2Deg);
float clamp = Mathf.Clamp(angle, -clampedAngle, clampedAngle);
this.transform.rotation = Quaternion.AngleAxis(clamp, Vector3.up);