• 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 Eqric · Jun 08, 2012 at 10:01 AM · rotationgravitymathbulletsin

bullet rotation as its affected by gravity

Hi, i am trying to get a bullet to rotate as it moves and is affected by gravity. So if the bullet speed in 0m/s it will just rotate 90degrees and fall straight down. My plan was to "make" a triangle of the "start" and "end" position of the bullet, ofc the start and end position changes alot during the bullets flight. alt text

So my code looks like this

 tempDistance = Vector3.Distance(startV,endV);
 angle = Mathf.Rad2Deg * (Mathf.Asin(hightdecrease/tempDistance));
 Vector3 test = new Vector3(angle,0,0);
 transform.Rotate(test);

highdecrease is B in the picture above and i think tempDistance will be C.

But this doesn´t seems to work at all, i get very strange angles. Is the math correct?

Untitled.gif (3.6 kB)
Comment
Add comment · Show 1
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 Fattie · Jun 08, 2012 at 10:53 AM 0
Share

What the hell dude ? You're using a game engine with a full physics system! Heh!

it will totally DO all that for you. Just throw the bullet and start it spinning, Unity will do everything.

2 Replies

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

Answer by Common_Horse · Jun 08, 2012 at 10:19 AM

You could try this:

 //This would be the maximum speed of you bullet
 float maxSpeed = 900;
 
 //This is where the bullet was last frame
 Vector3 lastPos;
 
 void Update () {
 //Find the velocity in m/s
 float velocity = (lastPos - transform.position)/Time.deltaTime;
 
 //Set up a ratio that will be used to rotate the bullet. If the velocity is maxSpeed, then the rotation will be 0 (forward, else it will rotate towards facing down (Assuming that +Z is your forward axis)
 
 transform.eulerAngles = new Vector3(velocity/maxSpeed * 90, transform.eulerAngles.y, 0);
 
 //Set lastPos so we can get the velocity next frame!
 
 lastPos = transform.Position;
 
 }


Very rough, but if you implement code like this, it should do what you asked!

-AJ

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
avatar image
0

Answer by Eqric · Jun 08, 2012 at 10:30 AM

Thanks mate, i give this a try!

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 Common_Horse · Jun 08, 2012 at 10:50 AM 0
Share

No problem man :)

If you need me to fix up the code, just give a yell!

-AJ

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Shoot an object and have it move based on rotation 1 Answer

My 2d spawned bullet prefabs will not fly up, just fall 3 Answers

Rotation approximation issues using Quaternion.LookRotation 0 Answers

Lookat Direction by AddTorque? 0 Answers

make child joint in joint hierarchy point upwards 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