• 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
2
Question by headkitgames · Feb 27, 2013 at 10:24 AM · addforcetrajectorymissileparabolic

rocketscience - how to find out what force is needed to hit a specific target

hi folks!

I have two plates with different positions in space like shown in the image. I need to find out what side-force is needed to shoot a misile from one plate to another. the up-force is given, the rocket has mass = 1.

alt text

I need to calculate the side-force that is needed to hit the second plate in its center to use it in

missile.rigidbody.AddForce(new Vector3(SIDEforce,UPForce, 0));

by only using the given up-force and the distance-vector between the two plates. any hints? thnx!

EDIT: the second plate is meant to be on a higher level than the first one. its y-position is bigger than the one of the first plate.

rocketscience.jpg (18.5 kB)
Comment
Add comment · Show 3
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 MickM · Feb 27, 2013 at 12:55 PM 0
Share

First step, calculate time for it to arrive back at the required y Starting point: http://hyperphysics.phy-astr.gsu.edu/hbase/traj.html#tra1

Second, divide the x distance by the time from step 1

Sorry I can't get the the first formula offhand (simple enough to make time the subject of vertical trajectory though)

Also http://blitzbasic.com/Community/posts.php?topic=68027 Or http://www.mathisfunforum.com/viewtopic.php?pid=35032 $$anonymous$$ight help

Good luck!

avatar image headkitgames · Feb 27, 2013 at 01:10 PM 0
Share

hey, thanx! shure, this would bring dy = 0-(((0.5*gravity*(time*time))+starty-endy)/time). but what about the time, from where would I get it?

avatar image MickM · Feb 27, 2013 at 01:15 PM 1
Share

Time to rise to highest point of flight = velocityVerticle/gravity If you are firing at the same y that you land, the overall time is just double the above (which you can put into step 2 from initial reply )

If not... A good resource is http://www.makingthemodernworld.org.uk/learning_modules/maths/04.TU.02/?section=13

Sorry it had been years since I did physics and don't have time to look more... Good luck again!!!

2 Replies

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

Answer by steakpinball · Feb 27, 2013 at 01:13 PM

Set rigidbody.velocity to the desired value.

The equation t = (-sqrt(2 * a * y - 2 * a * y_0 + (v_y0)^2)-v_y0) / a will give you the time it takes to move in the y direction. Use that in v_x = (x - x_0) / t to get the initial horizontal velocity. Where:

  • a is acceleration due to gravity

  • y is destination y position

  • y_0 is starting y position

  • v_y0 is initial y velocity

  • x is destination x position

  • x_0 is starting x position

  • v_x is desired x velocity

You can even make it one formula if you are feeling adventurous. Please don't make me write the literal code for this formula.

http://www.wolframalpha.com/input/?i=Solve+%5By%3D%3Dy_0%2Bv_0*t%2B%281%2F2%29at%5E2%2C+t%5D http://www.wolframalpha.com/input/?i=Solve+%5Bx%3D%3Dx_0%2Bv_0*t%2C+v_0%5D

Comment
Add comment · Show 2 · 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 headkitgames · Feb 28, 2013 at 09:37 PM 0
Share

really nice, thanx. So I now have something like

     float y = closestPlate.transform.position.y;
     float y_0 = transform.position.y;
     float v_y0 = jumpVelocity; // ??? HOW TO CALCULATE? UPFORCE HERE IS 700
     
     float x = closestPlate.transform.position.x;
     float x_0 = transform.position.x;
     
     float v_x0 = (x - x_0) / (float)( ($$anonymous$$athf.Sqrt (2 * $$anonymous$$athf.Abs(Physics.gravity.y) * y - 2 * $$anonymous$$athf.Abs(Physics.gravity.y) * y_0 + $$anonymous$$athf.Pow(v_y0, 2) ) - v_y0) / $$anonymous$$athf.Abs(Physics.gravity.y) );

     pathBullet = (GameObject)Instantiate(pathBulletPrefab);
     pathBullet.transform.position = transform.position;
     
     pathBullet.rigidbody.velocity = new Vector3($$anonymous$$athf.Sign(distanceVectorToNextPlate.x)*v_x0, v_y0 , 0);

but how could I now calculate the starting-velocity v_y0 from my starting UPForce ?

avatar image headkitgames · Mar 01, 2013 at 10:36 PM 0
Share

the velocity v_y0 from UPForce is calculated via

 float v_y0 = jumpVelocity * Time.fixedDeltaTime; // rigidbody.mass = 1

that works fine, but the x-velocity is way to high! how could that be...?

avatar image
1

Answer by Tarlius · Feb 27, 2013 at 12:48 PM

I think you want to use velocity, not force.

AddForce is for applying a constant/varying force over time. While you could work out the force you would need to apply for 1/60s (or whatever your physics simulation is running at) to get the required velocity, it'd be easier to just use velocity.

I'm pretty sure you'll be wanting this to solve the problem. I'm going to keep thinking on it for a more specific solution because this is a pretty interesting question :)

By the way: there will be times when it will be impossible to hit both with a fixed starting upwards velocity. Is that intended? Or have I misunderstood the question and you actually mean to apply force throughout the simulation (which won't produce the parabola in your diagram) and we're looking at something more like a homing missile?

Edit: Also- is the second plate always at ground level? I think its solvable even if not, but it would probably simplify things a lot

Comment
Add comment · Show 2 · 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 headkitgames · Feb 27, 2013 at 01:03 PM 0
Share

hey, thanx for answering. I think using addForce is the right way to force an object to move. think of it as giving an impulse to the object, only for one moment. due to inertia of masses it will flow on a parabolic path. the second plate is meant to be on a higher level than the first one.

avatar image Tarlius · Feb 27, 2013 at 01:54 PM 2
Share

From the docs:

"A typical example where you would change the velocity is when jumping in a first person shooter, because you want an immediate change in velocity."

As I said, you can achieve the effect by applying a force for one physics frame (which would be equivilant to applying the force constantly for 1/60 seconds), but its easier to do it with velocity.

If you apply a constant force of over 9.81 in the y direction, you will never come down. It will follow a parabola because of gravity, lack of upwards thrust (net acceleration downwards) and a constant horizontal velocity.

Anyway, it seems I've misread the question. I thought the start-point was where the rocket is in the diagram and it had to go through both. The problem is much simpler ^^;;

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

14 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

Related Questions

Question on projectile motion without using transform.translate or rigidbody on 3D with offset height between targets 0 Answers

Facing direction of missile 1 Answer

Trajectory problem with addforce coordinates 1 Answer

Calculate Velocity of Impulse 0 Answers

Rocket slightly wrong trajectory 2 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