• 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
-1
Question by user-1559 (google) · Mar 20, 2010 at 05:11 AM · rotationaxis

How would i lock a desired axis?

I would like to know how to lock an axis to keep an object from rotating on it. I am using JavaScript and I need the Z axis to be locked, due to the Z axis's value changing during the rotation of the X and Y axis's due to joystick I am new to Unity3D and scripting altogether but so far this is the only trouble i have came across. Thanks in advanced; Dylan Wright

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by e-bonneville · Mar 20, 2010 at 02:31 PM

You might have a look at either of these answers:

"How would I lock a desired axis"

"How to set a single axis rotation of a gameobject"

Comment
Add comment · Show 1 · 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 user-1559 (google) · Mar 20, 2010 at 03:19 PM 0
Share

i couldn't get anything out of them i tried some of the codes but my object still rotated on the Z axis some when i moved the joystick up adjusting the Y axis. If it helps i'm looking for something like the $$anonymous$$ouseLook Script but i can't use it on this object because I've used it on another object and it produces errors when used on two objects.

avatar image
0

Answer by StephanK · Mar 20, 2010 at 07:03 AM

Take a look at this answer: http://answers.unity3d.com/questions/4011/how-do-i-lock-out-a-axis

Comment
Add comment · Show 2 · 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 user-1559 (google) · Mar 20, 2010 at 01:48 PM 0
Share

i checked that out but it says thats for position but i tried to change "position" to "rotation" and it didn't work for some reason, it looked like it would, here is my script :

var speed = 3.0; var rotateSpeed = 3.0;

function Update () {

     var controller : CharacterController = GetComponent(CharacterController);
     
     transform.Rotate(Vector3.up, Input.GetAxis ("J1Up") * rotateSpeed, 0);

     

}

avatar image StephanK · Mar 21, 2010 at 05:58 PM 0
Share

You are using '0' as 3rd parameter of the Rotate function. This is equal to Space.World. The default would be Space.Self and that should work for you. Space.World let's your object rotate around (0,1,0) regardless of your object's local y-axis. You should always use the built-in enums ins$$anonymous$$d of ints. This helps clarifying your code a lot.

avatar image
0

Answer by user-1559 (google) · Mar 20, 2010 at 04:18 PM

I fixed it, for some reason when i duplicated the MouseLook Script before i must have left out something, if using the MouseLook script to control two different options with two different inputs just change this :

public class MouseLook : MonoBehaviour {

to something like this :

public class MouseLook2 : MonoBehaviour {

and it will work just fine. It did for me anyways. Thanks for the help though i figured it out on my own.

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

simple game spinner 0 Answers

90 Degree stopping rotation on y-axis issue 0 Answers

Transform.Translate but ignore rotation on one axis 0 Answers

Change rotation axis when importing from Maya 2 Answers

C# - Rotation problem 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges