Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Andreapigna · Apr 25, 2014 at 06:53 PM · rigidbodyplayerai

Calculate direction thrown projectile (rigidbody) (Js)

Hi, i need help with a simple AI... I need my enemy to throw a GameObject against my player...but i need the gameobject to do like in reality: i mean, if i need to throw a ball against something, i have to calculate the direction and the force to put into the ball to hit the target. How can i say this to a script? My ball (the projectile) has a rigidbody, so i guess i need to calculate the velocity etc...how can i do this? Thank you a lot!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by koray1396 · Apr 25, 2014 at 07:22 PM

way 1: you should go backwards. say if you throw something with an angle of a and with a velocity of v, it will go for a distance of d.

the equation would be something like this,

(cosa)(2 v * sina) / (gravity) = d

one approach would be fixing the velocity, and finding the angle;

cosa sina = (d gravity) / (2 * v)

sin2a = 2 (d gravity) / (2 * v)

a = arcsin(2 (d gravity) / (2 * v)) / 2

hope there is no mistake in the above, but this would be the general idea.

and you would know that the object would travel max. if it's thrown at 45 degrees. So, before above, you would calculate distance with fixed velocity and 45 degree angle, if it's lower than required, you would find the velocity with 45 degrees.

another way:

in lastupdate, try some angles and velocities and iterate them for a solution, then apply them for real in the next update.

last way:

store some values for angle and velocity (or force) after testing, and use them when needed.

no code provided, but I'm sure you can figure out from here.

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
avatar image
0

Answer by Cherno · Apr 26, 2014 at 02:36 AM

See this thread:

Calculate force applied to rigidbody to make it land at specific location

Specifically, the link in Aldonaletto's answer:

Shooting a cannonball.

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

22 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

Related Questions

NavMesh flee. Ai flee from player. 4 Answers

Rigidbody movement 1 Answer

player to kill ai 0 Answers

Attach a Player to a moving GameObject 0 Answers

Parent Object 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