how to limit the rotation of a game object in unity3d

Prachi Joshi

I am making a game where there is a tank that shoots some objects. I want to rotate the gun of the tank in between the llimits of -90 to 90 degrees in "X". I used transform.rotate but it rotates the gun with some float values (0.0 to 1.0) and the rotation I see on the inspector is something different. How to solve this issue?

David

Use below code from Mathf class

static float Clamp(float value, float min, float max); 

e.g.

var angle = Mathf.Clamp(angle, 90, 270);
Quaternion target = Quaternion.Euler(0, 0, angle); // any value as you see fit
transform.rotation = target;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I limit head rotation in Unity3D Google Cardboard?

From Dev

How to move a game object in the forwrard direction of an other game object Unity3D

From Dev

Unity3d - How to make method calling from another class that belongs to another game object efficiently

From Dev

How to have a Game Object remove itself from a list? (Unity3d)

From Dev

How can i know touched which game object with Unity3D

From Dev

Unity3D checking if a point is inside a game object

From Dev

Unity3D async game object instantiation

From Dev

How to design a game in Unity3D which is viable for patching?

From Dev

How to install Unity3d game engine on Ubuntu

From Dev

How to horizontally center a unity3D game in a div?

From Dev

In Unity3D game engine, how to make a delay?

From Dev

How to install Unity3d game engine on Ubuntu

From Dev

How to setup Parental gate for game developed in UNITY3d?

From Dev

How to horizontally center a unity3D game in a div?

From Dev

OpenCV rotation (Rodrigues) and translation vectors for positioning 3D object in Unity3D

From Dev

How to change rigs spine rotation in unity3d, using camera rotation?

From Dev

How to Limit (clamp) Y axis Rotation for transform.rotatearound Unity

From Dev

How to make an object to glow in unity3d

From Dev

How to convert class object to JSon string in Unity3D?

From Dev

How to convert class object to JSon string in Unity3D?

From Dev

trying to keep a game object within the screen left and right bounds in unity3d

From Dev

How can I find the rotation of the head in Google Cardboard Unity3D?

From Dev

How can I find the rotation of the head in Google Cardboard Unity3D?

From Dev

Limit object to screen edges along x axis - Unity3d

From Dev

How do I add the rotation, scale and translation of my object to my vertex in Unity 3D

From Dev

How to draw a monochromatic background in a 2d game with unity3d?

From Dev

Unity3D Slerp rotation speed

From Dev

Rotation angle constraints in Unity3d?

From Dev

Unity3D Slerp rotation speed

Related Related

  1. 1

    How do I limit head rotation in Unity3D Google Cardboard?

  2. 2

    How to move a game object in the forwrard direction of an other game object Unity3D

  3. 3

    Unity3d - How to make method calling from another class that belongs to another game object efficiently

  4. 4

    How to have a Game Object remove itself from a list? (Unity3d)

  5. 5

    How can i know touched which game object with Unity3D

  6. 6

    Unity3D checking if a point is inside a game object

  7. 7

    Unity3D async game object instantiation

  8. 8

    How to design a game in Unity3D which is viable for patching?

  9. 9

    How to install Unity3d game engine on Ubuntu

  10. 10

    How to horizontally center a unity3D game in a div?

  11. 11

    In Unity3D game engine, how to make a delay?

  12. 12

    How to install Unity3d game engine on Ubuntu

  13. 13

    How to setup Parental gate for game developed in UNITY3d?

  14. 14

    How to horizontally center a unity3D game in a div?

  15. 15

    OpenCV rotation (Rodrigues) and translation vectors for positioning 3D object in Unity3D

  16. 16

    How to change rigs spine rotation in unity3d, using camera rotation?

  17. 17

    How to Limit (clamp) Y axis Rotation for transform.rotatearound Unity

  18. 18

    How to make an object to glow in unity3d

  19. 19

    How to convert class object to JSon string in Unity3D?

  20. 20

    How to convert class object to JSon string in Unity3D?

  21. 21

    trying to keep a game object within the screen left and right bounds in unity3d

  22. 22

    How can I find the rotation of the head in Google Cardboard Unity3D?

  23. 23

    How can I find the rotation of the head in Google Cardboard Unity3D?

  24. 24

    Limit object to screen edges along x axis - Unity3d

  25. 25

    How do I add the rotation, scale and translation of my object to my vertex in Unity 3D

  26. 26

    How to draw a monochromatic background in a 2d game with unity3d?

  27. 27

    Unity3D Slerp rotation speed

  28. 28

    Rotation angle constraints in Unity3d?

  29. 29

    Unity3D Slerp rotation speed

HotTag

Archive