• 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 KDX2 · Mar 22, 2015 at 04:19 PM · physics

Ballistic Trajectory of a Projectile

Hi guys, I wonder ot make a script which "draws" the path of a projectile and which after that fires the object on it. Let me show you my point of view.alt text

Now, as far as I'm concerned, I should use the following formulas:

  1. x=x0 + vx*t (or x=v0*cos(alpha)*t) and deltay=v0y*t-1/2g*t^2 (or y=v0sinalpha*t-1/2g*t^2). With those I'll fix some points form the parabola, which later I'll somehow connect or use transform to move the object from one to another.

  2. The bigger problem for me comes with the velocity. What I'll be given will be the angle to the horizon, v0, I can loop the time somehow, so "t" is in also, max H, max R(range) but I don't have v0x nor v0y. I know the formulas vx=v0*cos(alpha) and vy=v0*sin(alpha)-g*t. What I can't solve out is how to calculate the magnitude of the vectors on the following point. vector v=v0 only at the begining and in order to get the next 'v'-s first of all we should know what the magnitudes of v0y and v0x are. So, if you have any formula for that, please share it with me. :)

The aim of the script, except making of a trajectory, is to fire the object with real-like speed. I mean, it should reduce it attacking the maxH and then accelerate it downwards.

I'm not about to make the script to target at sth and then shoot it with objects but simply to model the process. Now, there are things like Impulse and friction which also affect the trajectory but I couldn't find any formulas of that. I'm not sure how to compute the lenghts of v0y and v0y at the points which appear after point [0;0]. If you have the patience please explain me how it should look or work or both, what formulas should I use, because obviously those aren't the best. I've read numberous topics like:

https://vimeo.com/8900520

http://answers.unity3d.com/questions/248788/calculating-ball-trajectory-in-full-3d-world.html

But I just don't get the way they describe the process nor where the h those formulas came from. I would be very grateful if someone respond to my question and sorry for my English, I'm not a native speaker. :)

ng1.png (10.2 kB)
Comment
Add comment · Show 4
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 Nymisu · Mar 25, 2015 at 02:21 PM 0
Share

This is complex enough to have a solution in the asset store: https://www.assetstore.unity3d.com/en/#!/content/12306

The maths per say aren't overtly complex, but drawing the accurate representations in 3D space is the difficult part. For the maths, see: http://en.wikipedia.org/wiki/Trajectory_of_a_projectile

avatar image Glurth · Mar 25, 2015 at 03:00 PM 0
Share

Are you using any unity components like rigid body? Or are you trying to compute the positions and velocity's manually. If you are interested only in the end result, and not how to do the parabolic computation: I suggest you attach a rigid body to your projectile, set a gravity value, then simply set the rigidbody's initial velocity.

The game engine will then compute it's new position and velocity every frame. You can check/adjust the rigidbody's velocity at anytime.

To add air-resistance, you will want to ADJUST the rigid bodies velocity every update cycle, and reduce it based upon it's magnitude (squared). (the faster it goes, the more air resistance)
eg newV =Vnow.normalized* ( Vnow - (0.1f*(Vnow.magnitude*Vnow.magnitude)) Where 0.1f is the "amount" of air resistance.

avatar image KDX2 · Mar 25, 2015 at 11:13 PM 0
Share

Actually, the usage of the buit-in physics engine is the thing I'm trying to avoid chiefly. However, yes, I would use the rigidbody option and the gravity should be saved in a variable but it's not so important whether will be used the Unity one or my own... Thank you for the link, I've read this page maybe 3 times but misteriously why I omitted 2 formulas which now caught my eye. Thank you, once again if there is sth. I'll ask again :)

avatar image Zodiarc · Mar 26, 2015 at 12:33 PM 0
Share

I don't know if it's a good idea, but why don't you just set the shoot angle, the muzzle velocity and let the physics system handle the rest? (Didn't work a lot with it though, so sorry if I suggest something stupid here)

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

2D 360 degress platformer example needed 0 Answers

How to make Character Joint rotate towards a rest position? 0 Answers

Player object parallel -1 Answers

AddForce has no effect on my cannonball. 3 Answers

Connecting SpringJoint2D to Rotating Rigidbody2D With Correct Anchor 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