Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Selenor · Aug 10, 2015 at 04:26 AM · rotationrandommovecoroutinesboat

Random rotation along the y axis

Hi! I have a boat that I'm trying to get to move around my map randomly. I have two coroutines. One for movement and one for rotation. Both are called as soon as the game starts. The movement code is:

 IEnumerator Move() {
     yield return new WaitForSeconds (0.05f);
     transform.position += Vector3.forward * Time.deltaTime * thrust;
     StartCoroutine (Move ());
 }

The rotation one is exactly the same except the wait time is longer and the code I'm using is:

     Vector3 euler = transform.eulerAngles;
     euler.z = Random.Range(0f, 360f);
     transform.eulerAngles = euler;

However this of course makes the ship instantly rotate but I've yet to find a way to make the rotation gradual while still keeping it random. That's the first issue. Secondly, when the ship does rotate it doesn't change movement direction. That is, if the ship is heading, say north and the random rotation flips it around, it will continue heading north, even if the bow is facing the opposite direction. I thought the code I have would account for that but apparently somethings wrong. I'm really just focused on the first problem and I think eventually I could figure out the second, but I figured if I'm posting one, why not post the other?

Thanks!

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

Answer by allenallenallen · Aug 10, 2015 at 04:26 AM

Use this to slowly rotate:

http://docs.unity3d.com/ScriptReference/Quaternion.Lerp.html

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 Selenor · Aug 10, 2015 at 06:09 AM 0
Share

Ah see I found that earlier but you have to use a transform from another object right? And I don't wunna muck up the scene by adding cubes just to get their transform I was hoping it could be contained in just the boat.

avatar image allenallenallen · Aug 10, 2015 at 06:11 AM 1
Share

You can. Just declare yourself a few eulerAngles within the script. Remember that you can make rotations simply by declaring a Vector3. You don't need another object to do this.

http://docs.unity3d.com/ScriptReference/Quaternion-eulerAngles.html

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

special move with a cube. 1 Answer

How to change the rotation of the circle spawn? 1 Answer

Randomize shape.rotation for a particle emitter shape, sub emitter instance 1 Answer

Random rotation of instantiated prefab along one axis 2 Answers

how can i make a working boat in unity? 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