Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 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 /
avatar image
2
Question by jyounger · Aug 15, 2011 at 04:35 AM · physicsprojectiledrawtrajectoryarc

Aim preview for projectile trajectory

I need to calculate and draw an arc showing the trajectory that a projectile will take when it is launched. This is for a 2d side-view game involving physics and gravity. You pull back to aim and adjust your shot strength, then release to shoot your projectile, in this case a ball... not a bird ;). The ball is being launched by setting it's velocity along the vector chosen during aiming.

Currently I am making an arc by shooting smaller projectiles and using the trail renderer, but this is NOT a good solution as it is very slow to update the actual arc and lags behind the aiming a lot when adjusting your aim. I know there is a way to calculate a real-time trajectory arc for a physics based object, because I've seen it in the Rochard trailer (Unity game coming out for PSN). You can see the trailer here: http://www.youtube.com/watch?v=j-ULKB1-8Ko

As you can see in the video, the trajectory path is being updated instantaneously as the aim is adjusted. This is the effect I am looking for. I have scoured UnityAnswers for a solution. I've seen other people ask the same question, but so far the only answers I've seen simply don't provide the effect I am looking for. Any help would be greatly appreciated :)

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 jyounger · Aug 15, 2011 at 06:58 AM 2
Share

Okay, I've done a little research on the matter and it seems that I have all the information available to me that I need in order to calculate the trajectory properly.

Apparently all that is needed is the initial velocity, the mass, the angle of launch, the drag, and the acceleration of gravity. All of these are know at any given time. The question is, how to actually do the calculation. If someone could explain I would appreciate it.

I also understand that I should be populating an array of points based on this calculation, using some arbitrary time step. I can then connect the dots, so to speak, in order to draw the path of the trajectory. That actually seems like the easy part. I just need the basic formula for calculating the trajectory.

As an example, this applet is doing EXACTLY what I need to do: http://www.rabidgeek.net/physics-applets/projectile-motion/

All I need is the method they're using :)

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by jyounger · Aug 17, 2011 at 07:28 PM

Actually, I take it back. After looking at the Rochard trailer again, it seems that the trajectory being drawn and the actual flight path of the boxes being shot are in fact a parabolic trajectories that don't take drag into account.

I've talked to two math guys about this (including the fellow who made that physics applet I linked to) and I've gotten two different answers, neither of which has worked out very well:

 X = initialVelocity*cos(initialAngle)
 Y = initialVelocity*sin(initialAngle)
 
 loop N points times(
     X = X - (1/2) * drag * (velX*velX) * tStep/mass
     Y = Y - (1/2) * drag * (velY*velY) * tStep/mass - grav*tStep
 )

and

 X = X + mass/drag*initialVelocity*cos(initialAngle)*(1-e*(-drag*tStep/mass))
 Y = Y + mass*gravity/drag*tStep+mass/drag*(initialVelocity*sin(initialAngle)+mass*gravity/drag)*(1-e*(-drag/mass*tStep))

The first one actually works a bit better, though drag appears to only be affecting things in a leftward direction. It's hard to tell though because the gravity is behaving very strangely and seems to change directions depending on the initial angle.

The second one doesn't seem to even begin aiming in the proper direction, which at least the first one does.

Man, why is this so hard :(

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

2 People are following this question.

avatar image avatar image

Related Questions

How do I arc a rigidbody so it lands on a target? 2 Answers

2D projectile trajectory prediction 2 Answers

I want to find out how to make a projectile home in on a target with an "arc". 1 Answer

Arcing projectile using physics 0 Answers

How to: Lead on a projectile trajectory. Can't get T without angle without lead without T without angle etc... 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