• 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 POLYGAMe · Jun 06, 2011 at 12:39 AM · rotatecontrolstop

How to stop rotation?

Hi there,

I have a bunch of enemies in my 2D shooter that I want to spin on to the screen and then stop at rotation points 0, 0, 0. I know how to do this with time... but how do I stop rotation at a particular angle, rather than "stop rotating around Z after 2 seconds"? This would give me much more control.

I'd also use the WaitForSeconds while the enemies shoot, then rotate off the screen again. I have looked at Rotate.toward but can't work it out properly.

Any help muchly appreciated!

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

1 Reply

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

Answer by testure · Jun 06, 2011 at 12:49 AM

you could check the eulerAngle.z each frame and if it's within your range, stop updating the rotation. The more direct approach would be to rotate to a given angle in the first place, rather than rotating by time.

For this type of thing I usually use iTween, which makes it one line of code.

 iTween.RotateTo(gameObject, eulerAngles, Time);


Comment
Add comment · Show 6 · 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 POLYGAMe · Jun 06, 2011 at 01:40 AM 0
Share

Thanks, iTween looks very cool... I shall have a play!

avatar image POLYGAMe · Jun 06, 2011 at 01:54 AM 0
Share

Hmmm... can't seem to get it working... what's the proper syntax? $$anonymous$$y game object is called Enemy03.

avatar image testure · Jun 06, 2011 at 02:07 AM 0
Share

gameObject is an actual proper unity name. if you're attaching the script to the enemy, just use the keyword gameObject.

Otherwise, use your enemy's reference: GameObject enemy = transform.Find("Enemy03").gameObject;

avatar image POLYGAMe · Jun 06, 2011 at 02:38 AM 0
Share

Okay, do I replace eulerAngles and Time with floats? Because I tried that and it didn't work...

avatar image testure · Jun 06, 2011 at 02:43 AM 0
Share

You might want to check the documentation- it's pretty clear what goes there ;)

eulerAngles would be a Vector3 of euler angles, and Time is a float.

Show more comments

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

2 People are following this question.

avatar image avatar image

Related Questions

How to make camera position relative to a specific target. 1 Answer

How to rotate character with mouse and camera 0 Answers

how do i stop/exit a coroutine? 1 Answer

Rotation control (C#) 1 Answer

Control the Animation 1 Answer


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