Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by arteetmarte · Nov 15, 2019 at 05:34 AM · physicsrigidbody

AI detect incoming rigid body position placement to catch it

Hello, I need help figuring out two physics based scenarios within my game. I have searched high and low here and on Stack with none of the answers providing what I actually need nor a good solution. I apologize in advance if there is an undiscovered thread on my behalf.

Regardless, the first scenario is that in my game the AI must “catch” an incoming rigid body; I have blendtrees set up for the different animations (up, left, right, etc) depending on where the rigid body would be coming from. The issue is, actually getting the AI to be aware or know where the object would be relative to them when they are going to attempt a catch (this would depend on the velocity/angle/height of the incoming projectile). So I’ve been basically looking for a solution that would tell the AI exactly the point of intersection before the object is even there to know whether it fires an animation to lunge left to catch, or right, or jump, or middle down etc. including the fact if the object would be beyond their reach.

I’ve used physics simulation algorithms and all but they either are to slow or not accurate for what I need. I don’t know if it’s due to the fact that the object in question that I’m trying to solve for has a drag value of 0.336 and a mass of 0.146. I currently have it set up that the AI game object has a Distance SqrMagnitude code triggering when the object is near them or incoming to trigger the function and this works well to detect the incoming rigid body but I’m just missing the fine tune part of letting the AI know exactly where it will be once it reaches the AI in order to fire off the correct animation and the AI could actually catch it.

Side note, I have the code setup that once it enters the trigger sqrmagnitude range the catch animation fires and the AI does catch it BUT, the rigid body visually and collision wise will pass the AI which is in animation and then all of a sudden the object will appear in its hand. Therefore, if the object is in the air and the AI “catches” it, the object keeps going past it and hits the floor or continues past it and then just appears in its hand after. I have them both set to continuous collision detection and all yet it still happens.

Secondly, this part kind of ties in with the first but not exactly. I’m having an issue as well finding a real good put together solution to know exactly where a rigid body would land on the floor if it’s shot up in the air. So the AI navmesh would run to this spot to try and catch it before it lands; so I am trying to get the vector coordinates of that exact landing spot from as soon as an object is in motion. I’ve tried numerous solutions online with mixed results because most don’t even take into account, like before, the objects drag which I have at a 0.336 value with a mass of 0.146 just as before.

If anyone could help me out with this in any way, shape or form, including even pointing me to the right place online because I’ve honestly searched everywhere.

Lastly, really sorry about the length of the post lol.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by lgarczyn · Nov 16, 2019 at 05:13 AM

To predict the position of the object, you simply need to increment the position by the velocity * deltaTime, and decrement the y velocity by gravity * deltaTime, and repeat for every frame you want to simulate. It's a actually cheaper than it sounds.

Calculating drag is a bit harder, by can be done: https://answers.unity.com/questions/652010/how-drag-is-calculated-by-unity-engine.html

Again, repeat every "simulated frame".

Once you know the position it will have when passing the target (can be done with raycasts), simply calculate the time it took to get there, and wait for that time minus your animation time to start the animation.

Once the AI catches the ball, make the rigidbody kinematic or disable it in some way.

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

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

Related Questions

Why is my Rigidbody freaking out like this? 0 Answers

stack-type game problem (blocks fall). bloques se caen en juego de apilar cajas 0 Answers

GetAxis being missed in FixedUpdate work around? 1 Answer

Smooth motion rigidbody 1 Answer

Collision Between Two Child GameObjects 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