Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 Tommy 1 · Apr 15, 2011 at 10:17 PM · rotationrotateangle

Rotating an object - problem with angle.

Ok, I am new to coding... I made this own variation of code out of some examples and it works basically as planned = I can turn a model 120 degrees by left/right arrows (horizontally). I can also turn/tilt the model vertically but now it rotates weirdly (up/down). At "0 degrees" = not rotating the object sideways (horizontal), the vertical rotation works fine, but when I look at the model from a 120 degree angle, the up/down rotation bends sideways.

private var rotate : float = 0.0; // rotate horizontal private var rotateto : float = 0.0; // rotate horizontal private var easinout : float = 0.05; private var rotatev : float = 0.0; // rotate vertical private var rotatetov : float = 0.0; // rotate vertical var Target : GameObject;

function Update() { rotate = rotate + (rotateto - rotate) * easinout; Target.transform.rotation = Quaternion.identity;

// rotate vertical (up down) rotatev = rotatev + (rotatetov - rotatev) * easinout; Target.transform.rotation = Quaternion.identity; Target.transform.Rotate(rotatev, rotate, 0);

if (Input.GetKeyDown("left")) { rotateto += 120.0; }

if (Input.GetKeyDown("right")) { rotateto -= 120.0; }

if (Input.GetKeyDown("up")) { rotatetov += 20; }

if (Input.GetKeyDown("down")) { rotatetov -= 20; } }

Comment
Add comment · Show 2
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 Marnix · Apr 15, 2011 at 10:36 PM 0
Share

@Redspot: What do you mean by "bending" sideways?

avatar image Tommy 1 · Apr 16, 2011 at 07:38 PM 0
Share

I mean that the model I rotate doesnt go up/down with up/down keys, ins$$anonymous$$d it goes up/down BUT it ALSO rotates to one side. (add a camera to a level, add a capsule (and a texture) + the code above, in Inspector add the capsule as Target and run. press up/down (works fine), rotate 120 and it doesnt turn up/down the same straight way.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Velketor · Apr 16, 2011 at 12:13 AM

turn off mouselook...or at least limit the constraints of your x, y, or z values.

Comment
Add comment · Show 3 · 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 AngryOldMan · Apr 16, 2011 at 12:37 AM 0
Share

where does it say he is using mouselook?

avatar image Velketor · Apr 16, 2011 at 02:00 AM 0
Share

his description describes a mouselook problem

avatar image Tommy 1 · Apr 16, 2011 at 08:07 PM 0
Share

No I do not have the mouselook code

avatar image
0

Answer by Tommy 1 · Apr 16, 2011 at 08:59 PM

Ok problem seems to be the object rotaes around its own axis, and not world axis. How can I get it to rotate around world axis? Adding Space.World to the end of Target.transform.Rotate(rotatev, rotate, 0, Space.World); doesnt help...

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Rotating without gimbal lock 1 Answer

Calc 30° left and x units forward from local forward axis 1 Answer

Rotating Joystick on Touch 0 Answers

How to rotate an object without using a timer 1 Answer

Set rotation on y-axis with angle relative to current position 0 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