Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
2
Question by lightingft · Jun 06, 2017 at 11:58 AM · physicsforcetrajectoryarrowballistic

Calculate force needed to reach certain point (AddForce)

Hello everyone, So I have the following system setup for an arrow shooting game:

  • A force (from 0 to a certain maximum value) is chosen by the player. Say force is F.

  • The angle (from 0 to 90) is also chosen by the player. Say degrees are D.

  • Afterwards, having the force and degrees, AddForce is used. Two forces are applied - one for X, and one for Y. F_Y is calculated like this: F * (D / 90f), and F_X = F - F_Y. Thus the force added is AddForce(F_X, F_Y)

  • The Arrow is fired. Gravity value is default. Arrows may have different weights (rigidbody). Distance between the starting position and end position are given.

I need a way to figure out the total force or just one of the forces needed to reach a SPECIFIC point (X and Y, Z axis is not used at all). I am aware that there are multiple X & Y possibilities, however, is there a way to know at least one of the forces (or the total) having only the following variables? (I need to find out this value in a script for different degree, distance and arrow weight values)

Thank you!

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
9

Answer by sysmaya · Jul 04, 2017 at 11:12 PM

This function calculate the Vector3 and speed for parabolic shoots. EJ: Shoot Bows, Shoot canons, etc.

     Vector3 calcBallisticVelocityVector(Vector3 source, Vector3 target, float angle){
         Vector3 direction = target - source;                            
         float h = direction.y;                                           
         direction.y = 0;                                               
         float distance = direction.magnitude;                           
         float a = angle * Mathf.Deg2Rad;                                
         direction.y = distance * Mathf.Tan(a);                            
         distance += h/Mathf.Tan(a);                                      
 
         // calculate velocity
         float velocity = Mathf.Sqrt(distance * Physics.gravity.magnitude / Mathf.Sin(2*a));
         return velocity * direction.normalized;    
     }

Comment
Add comment · Show 5 · 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 Serinx · May 28, 2018 at 03:32 AM 0
Share

Hello, Sorry to Necro the thread. Does this factor in the mass of the object being launched? Or is it assumed the mass is 1?

avatar image nextage575 · Dec 13, 2019 at 06:16 AM 0
Share

@sysmaya How to call this function?

avatar image puppeteer · Mar 21, 2020 at 01:32 PM 0
Share

Thanks, this helped me get the correct bounce direction of a ball to reach a point.

avatar image JMEJAY · Jul 07, 2020 at 10:50 PM 0
Share

Hey, any idea how to calculate this considering the drag of the rigidbody?

avatar image endasil_unity · Jul 23, 2020 at 08:14 AM 1
Share

Can you explain how the math works here? Why is direction.y distance * Tan(a)? why is h/Tan(a) added to distance? Basically the stuff from that point would be great if you could explain how it works.

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

150 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 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 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

Impulse Force not smooth 1 Answer

What is the parabolic formula for a 2D projectile's trajectory 1 Answer

I am interested in moving a ragdoll character only using Forces. 0 Answers

How do I get objects in front of the player to be blasted away? 1 Answer

How to make Cool Goal physics 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