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 Distant-Object · Jan 15, 2014 at 09:51 PM · physicstrajectory

Why is my game not following basic rules of projectile physics?

So I have an object with no drag that is launched a very far distance from a completely flat surface and lands again on this completely flat surface. In air the project should be under no force except of that of gravity. Prior to being launched I want to calculate the distance between the point it starts from and the point it will land on.

As wikipedia says the equation should be: d = (v^2 sin(2 angle) ) / g. What I have is:

 Mathf.Abs(((velocity * velocity) * Mathf.Sin(2 * angle * Mathf.Deg2Rad)) / Physics.gravity.magnitude)

But it's not working. The actual distance it travels is always a little less than what I calculate, for example what I calculated on my last launch was a distance of 2744.497 but instead got 2707.329. Please help me, this is driving me mad. I don't know if there is something that is preventing the projectile from acting like a real life projectile, or if my calculation is incorrect. I am even using doubles instead of floats to avoid floating point inaccuracy.

If it helps, I calculate the angle with:

 var angle : double = Vector3.Angle(direction, Vector3(direction.x, 0, direction.z).normalized);

Where direction is the direction the projectile is launched.

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 tanoshimi · Jan 15, 2014 at 11:15 PM 0
Share

A guess, but what value are you using for g? I think by default Unity only approximates it to 9.81.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Eric5h5 · Jan 15, 2014 at 10:06 PM

Probably there is accumulated discrepancy over time since physics is computed frame-by-frame, it's not all pre-computed. Using doubles is counter-productive since Unity only uses floats. Also the physics engine is just a vague approximation of real life; don't expect anything exact. If you do need something very specific and exact then it would probably be better to not use the built-in physics, but make something customized for your needs instead.

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 gfoot · Jan 15, 2014 at 11:43 PM

Make sure you disable drag on the rigid body. I wouldn't expect quite as much error as you're seeing in general.

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

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

21 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

Related Questions

Simulating a trajectory that takes collisions into account 2 Answers

Ellipticall Orbit like Spaceflight simulator 1 Answer

How to calculate the angle of a trajectory to hit the target 1 Answer

2D 360 degress platformer example needed 0 Answers

Bomb Trajectory for a "Water Canon" (Maths) 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