Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Justinger · Aug 08, 2016 at 04:42 PM · vector3euleranglesrocket

Adding vector locally for a rocket wobble

Hello, I am attempting to make a rocket that has a nice circular wobble around whichever direction it is flying. I have created a vector3 using sin and cos that can make an object rotate in a circle around it's up axis. However, I don't seem to know how to properly do the math to add this to the rocket, which can be at any arbitrary angle it finds itself in.

My goal is that depending on the rate and magnitude, the rocket will fly more out of control, as if it is damaged or not calibrated correctly, making a corkscrew path.

I left a couple lines of commented out test code in. I'm running out of ideas on how properly implement this. Any guidance would be much appreciated. Thank you.

alt text

 using UnityEngine;
 using System.Collections;
 
 public class wobbleCS : MonoBehaviour {
 
     public float wobbleRate = 10;
     public float wobbleMag = 0;
 
     // Update is called once per frame
     void FixedUpdate () {
 
         Vector3 rocketWobble = new Vector3(wobbleMag *(Mathf.Sin(Time.time * wobbleRate) ), 0, wobbleMag * (Mathf.Cos(Time.time * wobbleRate) )   );  
         Debug.Log("Debug: " + rocketWobble.x + ", " + rocketWobble.z + ". ");
         //transform.rotation = Quaternion.Euler(rocketWobble); // makes a nice circle around the up axis
         //transform.Rotate(Quaternion.Euler(rocketWobble).eulerAngles, Space.Self);  //this results in crooked rotations
         transform.rotation = Quaternion.Euler(rocketWobble) * transform.rotation; // identical results as the line above I believe
         
     }
 }


rotation-question.png (469.7 kB)
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 kamipwnz · Nov 08, 2020 at 02:11 PM 0
Share

Did you ever solve this? I really like the effect, but running into the same issue that it will not honor the direction from the spawnpoint. So it always moves in a straight line, no matter what the quaternion was.

avatar image Justinger kamipwnz · Nov 11, 2020 at 07:59 PM 1
Share

Yes, I got it working for my needs. I dug up my old code here:

 this.GetComponent<Rigidbody>().AddRelativeForce( (new Vector3(crooked$$anonymous$$ag, 1, 0)) * force); //crooked$$anonymous$$ag deter$$anonymous$$es how off-kilter the rocket should be, force decides how hard the thruster is pushing
                 this.GetComponent<Rigidbody>().AddRelativeTorque(Vector3.up * spinRate);  //makes the rocket spin

I add a relative force upwards, but make it slightly crooked with a variable called crooked$$anonymous$$ag. I also add a spin using relative torque. This results in it spinning and wobbling. I hope this helps.

1 Reply

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

Answer by jackmw94 · Nov 11, 2020 at 09:55 PM

I think this would be much easier if instead of calculating the actual angles that rocket will be at, you make use of the gameobject hierarchy.

These two screenshots show an example of the setup, the root object has a regular spin around its y-axis and the model object below has a constant x-axis offset:

Root object has spin

Model has a rotation offset


rocketroot.png (322.8 kB)
rocketmodel.png (361.4 kB)
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 Justinger · Nov 12, 2020 at 08:28 PM 1
Share

This is a good solution. I will add that it's important how the force is applied. Since the root is spinning, the model's position values should not change or your results would quickly become bizarre. So the rigid body could be placed on the root node and you could AddForce using the up vector of your model instead of the root. It's also worth noting that the rotation in the rotation script should be done using AddTorque rather than regular rotation because this is physics based.

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

57 People are following this question.

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

Related Questions

transform.eulerAngles of camera - changing the speed of rotation not working? 1 Answer

How do I make create a rotateable object that follows a raycast hit point? 2 Answers

Turn and Move Foward 1 Unit relative to Objects local direction 1 Answer

How to prevent Transform from going through walls? 2 Answers

Rotate some coordinates in relation to an object's rotation 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