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 Firedan1176 · Jul 12, 2014 at 05:19 PM · rigidbodydistancedynamicssinecosine

How to calculate the distance of an object with velocity?

Instead of calculating distance between 1 object and another, can I calculate the distance between an object and another, can I calculate the distance using the 'arch' an object with dynamics has (like a mortar firing)? Here's my example: f

exampl.png (5.3 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 tswalk · Jul 12, 2014 at 07:35 PM 0
Share

projectile trajectory:

http://en.wikipedia.org/wiki/Trajectory_of_a_projectile

good luck with that math! :) unforuntately I can't help you with that lol

1 Reply

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

Answer by alwayscodeangry · Jul 12, 2014 at 10:58 PM

Most of the trajectory equations can also be found here. I'm not 100% sure whether you're trying to get the horizontal distance or the arc length, so I've included both, and luckily Mathf has all the functionality we need:

 private static float GRAVITY = 9.8067f;
 
 public static float GetHorizontalDistance(float velocity, float launchAngle, bool degrees = false)
 {
     // convert to radians if necessary
     if (degrees)
     {
         launchAngle *= Mathf.Deg2Rad;
     }
 
     return (velocity * velocity * Mathf.Sin(2.0f * launchAngle)) / GRAVITY;
 }
 
 public static float GetArcLength(float velocity, float launchAngle, bool degrees = false)
 {
     // convert to radians if necessary
     if (degrees)
     {
         launchAngle *= Mathf.Deg2Rad;
     }
 
     // pre-calculate sine and cosine of launchAngle and square of velocity
     float sinAngle = Mathf.Sin(launchAngle);
     float cosAngle = Mathf.Cos(launchAngle);
     float vSquared = velocity * velocity;
 
     return (vSquared * (sinAngle + cosAngle * Mathf.Log((1.0f + sinAngle) / cosAngle))) / GRAVITY;
 }

You may need to swap out the const GRAVITY for Unity's value, depending on your usage case.

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 tswalk · Jul 18, 2014 at 06:17 AM 1
Share

that is some angrycode!... :)

(couldn't help myself.. I just like your pseudo name)

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

23 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

Related Questions

calculate the estimated distance travel based on the Force applied to Rigid Body 1 Answer

Enemy AI help with height check 1 Answer

Calculate where an object is going to land 0 Answers

Maintaining specific distance between two objects 1 Answer

real life:sin(2Pi)=0 unity Mathf.Sin(2Pi)=1.748456E-07 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