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 gilgada · Jan 04, 2012 at 05:14 PM · rotationphysicsanglecatapult

Trying to rotate my catapult's launch arm.

This is similar code to my last problem but the problem itself seems to be different.

As part of my catapult, there is an 'arm' that holds the projectile. The player is able to raise or lower this arm around its pivot, affecting the velocity of the projectile object upon launch.

The catapult arm is a gameObject holding two things: the visible catapult arm with mesh collider. another arm with no mesh renderer or collider, placed opposite the other arm, its purpose being to create the centre or rotation for the encapsulating gameObject.

Now, when the player presses up, the arm should raise unless it is already at 90 degrees to the base of the catapult frame. Also, when down is pressed, the arm should lower unless it is already at 10 degrees to the base.

The arm moves fluently, applying help I had previously from aldonaletto.

The problem I am facing is that for some reason when testing the arm seems to rotate in a full circle without restraint, only slowing down when it seems to be almost 180 degrees from its original position. The x rotation seems to peek around 90 and then as the arm moves through the catapult frame it carries on and the x rotation appears to decrease. It doesn't stop where I need it to.

My code is as follows:

gameObject.tag == "catapult arm";

function Update() { if(transform.Rotation.x < 90 && transform.Rotation.x > 10) { if(Input.GetKey ("up")) { transform.Rotation.x -= 0.01; } if(Input.GetKey ("down")) { transform.Rotation.x += 0.01; } } }

Comment
Add comment · Show 3
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 puelo · Jan 04, 2012 at 05:20 PM 0
Share

i might be very wrong here, but are you sure, that transform.Rotation.x is giving you a return value in full degrees?

From the Script Reference:

"The rotation of the transform in world space stored as a Quaternion. Unity stores rotations as Quaternions internally. "

avatar image gilgada · Jan 04, 2012 at 05:24 PM 0
Share

I really have no idea. The value I was referring to when testing is from the inspector Transform box with the catapult arm selected. I believe these are degrees.

avatar image puelo · Jan 04, 2012 at 05:27 PM 0
Share

$$anonymous$$aybe try to Debug this with:

Debug.Log(transform.Rotation.x); or print(transform.Rotation.x);

Before and After the If Statement.

1 Reply

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

Answer by syclamoth · Jan 04, 2012 at 05:28 PM

The number from 'rotation.x' and the 'x' component in the transform box are not the same. It's important to understand this- the three numbers in the transform box are a Euler Angle representation of the rotation!

If you use rotation.euler.x instead, it will give you a more correct number.

In this case, however, you should just use Transform.Rotate, since it manages all of that for you.

Comment
Add comment · Show 4 · 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 gilgada · Jan 04, 2012 at 05:32 PM 0
Share

How do I incorporate Transform.Rotate?

Am I to replace the transform.rotation.x? The intellisense does not show Rotate as a member of Transform...

avatar image gilgada · Jan 04, 2012 at 07:17 PM 0
Share

I changed the transform.rotation.x to transform.rotation.eulerAngles.x and it works perfectly. Thankyou for your help. :)

avatar image syclamoth · Jan 05, 2012 at 01:25 AM 1
Share

Oh, sorry, I wan't being clear. Rotate is a function of the object, not the class. Look it up in the documentation- it's there to help you! In fact, if everyone read the documentation before posting here there probably wouldn't be half as many questions.

tl;dr, use it like this-

 transform.Rotate(some amount);

this makes the Transform 'transform' rotate.

avatar image gilgada · Jan 05, 2012 at 01:32 AM 0
Share

thanks for the update, however your other advice of using eulerAngles was sound :) another thumbs up for you though

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

6 People are following this question.

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

Related Questions

physics & rotation question 1 Answer

Keep rotation when changing parent in Unity 3D 1 Answer

Moving forward in world space with rotation. 1 Answer

Turret Limitations on a Moving Object 0 Answers

limiting rotation to solid angle 5 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