How do i stop the texture(a quad) from rotating so much on X axis?

Viewed 20

I'm working on a game and in this game the trees are 2d , because of this i want them to rotate around the player (i used this script)

{
    public Transform target;

    void FixedUpdate()
    {
        transform.LookAt(target);
    }
}

but when i get to close to the quad it goes above me so

How can i limit the quad's rotation on X?

1 Answers

Your problem is simply that you can change A to rotate around B.

Method 1: B does not move, and A hangs the script to implement transform's RotateAround(vector3 point, vector3 axis, float angle) function For example A.RotateAround(B.position, Vector3.up, 30*Time.deltaTime); //A rotates around the y-axis of B.

Method 2: A does not move, A acts as a sub-object of B, and B hangs the script to achieve rotation, and then rotates with A, similar to simulating rotation around the central celestial body. For example: B.Rotate (Vector3.up, 30*Time.deltaTime, Space.Self); //B rotates around its own up direction, thus rotating with A.

Common methods of rotation:

(1) Rotate around the coordinate axis

public void Rotate (Vector3 eulerAngles, Space relativeTo = Space.Self);

or

public void Rotate (float xAngle, float yAngle, float zAngleSpace, relativeTo = Space.Self);

Where relativeTo = Space.Self means to rotate around its own coordinate system, and ralativeTo = Space.World means to rotate around the world coordinate system.

(2) Rotate a certain vector

public void Rotate(Vector3 axis, float angle, Space relativeTo);

where axis is the direction of the rotation axis, angle is the rotation angle, relativeTo is the reference coordinate system, and the default is Space.self. The function of this method is to rotate the GameObject object by angle degrees around the axis in the relativeTo coordinate system.

(3) Rotate around the pivot point

public void RotateAround(Vector3 point, Vector3 axis, float angel);

The function is to rotate the GameObject by an angle degree around the axis of the point.

Related