• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by blackshtormx · Feb 16, 2014 at 04:26 PM · rotationturrettank

Rotate on Z axis

Hello guys! I've problem with Z axis rotating... I've turret that is rotating by pressing z,x buttons, but turret is rotating like:

alt text

so, i decide to rotate it on Z axis. Here is code i am using:

 var speed : float = 5; 
 var backspeed : float = -5;
 
 function Update() {
 
 if (Input.GetKey("z")) 
 {
 transform.Rotate( Vector3, 0,speed*Time.deltaTime, 0,Space.Self); 
 } 
 
 if (Input.GetKey("x")) 
 { 
 transform.Rotate( Vector3, 0,backspeed*Time.deltaTime, 0,Space.Self); 
 }
 } 

So thanks for any help :)

capture.jpg (24.2 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by JeffreyD · Feb 16, 2014 at 04:57 PM

I'm using this below to do a simple rotation of a cube.

transform.Rotate (Vector3.up Time.deltaTime 100, Space.World);

So maybe it's the UP in Vector3 that you need. There also seems to be too many arguments.

http://docs.unity3d.com/Documentation/ScriptReference/Transform.Rotate.html

Try...

transform.Rotate( Vector3.up speed Time.deltaTime, Space.Self);

OR

transform.Rotate(0, 0, speed*Time.deltaTime, Space.Self);

I'm not clear on the use of Space.Self v.s. Space.World. I guess you can play with each to see which give you the effect you want.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Epic_PotatoGuy · Aug 18, 2017 at 04:54 PM

use transform.Rotate (new Vector3 (0, 0, 20) * time.deltaTime);

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

question about turret on tank 1 Answer

rotating a tank turret while the tank is rotating 3 Answers

Rotating turret floats off tank in a sideways circle. Cannon floats out of turret when rotating up. 0 Answers

Lock rotation of object 4 Answers

tank-tower rotation works unexpected 2 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges