• 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 tieTYT · Aug 17, 2011 at 07:36 AM · physicsrigidbodyprojectiletrajectoryarc

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

I have a cannon (the source) point, the projectile (a cannonball) and a target. How do I call the cannonball's rigidbody so it lands exactly on the target? I want the trajectory to be an arc shape. This is in 3D space (that is, it's not a 2D platformer like all the other similar questions seem to be asking about).

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 Waz · Aug 17, 2011 at 08:27 AM 0
Share

You have to do your own physics calculations. There is no exposed Unity functionality for that. I suggest you implement the case without drag.

2 Replies

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

Answer by Julien-Lynge · Aug 17, 2011 at 08:48 AM

First of all, if you want to spend money and exert minimum effort the free iTween package for Unity has an example project that does pretty much exactly what you're looking for ( http://itween.pixelplacement.com/examples.php ). The package of examples costs $20, so you may not want to go that route.

If you wanted to do it numerically / with realistic physics, you'd have to solve a few of basic physics equations. You have two variables that describe the motion: the initial velocity and the firing angle. Wikipedia has a great section on the parabolic equation you would need:

http://en.wikipedia.org/wiki/Trajectory#Uniform_gravity.2C_no_drag_or_wind

In a nutshell, you plug in your desired velocity or angle and range to get the required angle or velocity to hit your target. Then, turn on gravity for the rigidbody and set the initial velocity of the rigidbody. Assuming we're firing in the positive X direction:

rigidbody.velocity = new Vector3(desiredVel Mathf.Cos(desiredAngle), desiredVel Mathf.Sin(desiredAngle), 0f);

In any other direction the Y velocity is the same and you change the X and Z trigonometrically based on your angle around the Y axis.

If you wanted friction from the air this becomes a differential equation, and you should consult your local mathematician.

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 Julien-Lynge · Aug 17, 2011 at 08:51 AM 1
Share

BTW: just so we're clear, the case is exactly the same as for all the other 2D platformer game examples you mention, except that in those examples we assume that we're firing in the positive X direction. For an angle from positive X of theta, the amount of velocity in X and Z changes by:

 X = origVal * Cos(theta)
 Z = origVal * Sin(theta)

Once you fire off the projectile, you don't have to do any other math, as Unity will apply gravity for you.

avatar image
3

Answer by aldonaletto · Aug 17, 2011 at 10:01 AM

I answered a similar question some time ago - the cannon shoot at 45 degrees and the ball always land on the target position (unless the target runs away before). Clike here to read this answer.

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 neroziros · Aug 24, 2012 at 11:56 PM 0
Share

I'm looking for a way to make the same but with variable angles (from 30 to 80 degrees) any suggestions? Thanks in advance for your time!

avatar image AkooleGame · May 07, 2015 at 10:32 AM 3
Share

Link is broken.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Aim preview for projectile trajectory 1 Answer

Throwing a Spear 1 Answer

Innacurate terrain collision with fast rigidbody 1 Answer

Bullet projectiles with collision info without affecting others 0 Answers

Fireing a tank projectile. 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