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 /
avatar image
0
Question by hariprathaap · Nov 20, 2017 at 10:00 AM · dragballbouncetrajectoryprediction

How to predict where the ball will land after being hit by bat?

I'm working on a cricket game which uses the unity's own PhysX. I need to predict where the ball will land after it is hit by the bat. The fielder has to run toward the ball judging where the ball will land. The ball has some drag. I have searched a lot of solutions but nothing works...

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 NorthStar79 · Nov 20, 2017 at 10:55 AM 0
Share

can you share the code that you apply hitting force to ball and ball's rigidbody setting? this way we can give more precise suggestions.

4 Replies

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

Answer by Eno-Khaon · Nov 21, 2017 at 06:01 AM

Sorry, but I'm going to be a little lazy in this response...

I previously reviewed this subject (the most recent was here). I outline the general basis of the physics interactions per physics timestep, along with a basic idea of how to trace a path for them. Because Drag modifies the current force at any and every given point in time, it becomes more reasonable to simply run a quick calculation of the physics ahead of time and see how things match up.

So, to reiterate what I went over there:

 rigidbodyDrag = Mathf.Clamp01(1.0f - (rb.drag * Time.fixedDeltaTime)); // Per FixedUpdate()
 // This means that if your drag is equal to the framerate of FixedUpdate(), your object will lose 100% of its speed every frame
 
 velocityPerFrame = lastFrameVelocity + (Physics.gravity * Time.fixedDeltaTime);
 velocityPerFrame *= rigidbodyDrag;
 positionPerFrame += (velocityPerFrame * Time.fixedDeltaTime);


Then, to implement that in a simple example:

 // C#
 List<Vector3> positionList;
 // ...
 
 positionList = new List<Vector3>();
 // ...
 
 // Example maximum of 5 seconds
 int maxIterations = Mathf.RoundToInt(5.0f / Time.fixedDeltaTime);
 Vector3 pos = ball.position;
 Vector3 vel = ballRigidbody.velocity;
 float drag = ballRigidbody.drag;
 positionList.Add(pos);
 float elapsedTime = 0.0f;
 
 for(int i = 0; i < maxIterations; i++)
 {
     vel = vel + (Physics.gravity * Time.fixedDeltaTime)
     vel *= drag;
     pos += vel * Time.fixedDeltaTime;
     elapsedTime += Time.fixedDeltaTime;
     positionList.Add(pos);
 }


The moment the bat makes contact with the ball, you should have a new velocity value available for the ball, so this can be handled at that moment in order to determine where the ball will travel to. Every point at a height reachable by a player can then technically be considered valid and you'll know how long it will take the ball to reach that point based on how far into the List<> the position value is located. By default, FixedUpdate() runs 50 times per second, so the time to reach any given position can be easily tracked with this in mind.

To provide further accuracy (and, depending on your defined timeout, efficiency), either raycasts in the predicted direction of movement at each timestep or a hard height cutoff can be checked for contact with the ground and stop the calculations sooner.

Comment
Add comment · Show 3 · 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 hariprathaap · Nov 24, 2017 at 07:03 AM 0
Share

is there a way to find the ball trajectory at each bounce on the ground?

avatar image Eno-Khaon hariprathaap · Nov 24, 2017 at 07:53 AM 0
Share

I'm afraid I don't know all the formulas for Unity's PhysX implementation off hand, so I can't offer any sound advice in that regard.

I do know that Physic $$anonymous$$aterials influence how high it would bounce, but current rotation speed (Angular Velocity) is a factor in the direction it would bounce, as well as any potential irregularities or flaws in the physics interaction that could occur (which would just throw logic out the window by that point). I'm sorry to say I'm not fully familiar with the collision interactions.

avatar image JonPQ hariprathaap · Nov 27, 2017 at 04:48 PM 0
Share

you can add OnCollisionExit code.. which unity calls after your collision... then just read the currect velocity vector from the RigidBody.... and re-run your predictive code again for where it will land again.

avatar image
1

Answer by Grish_tad · Nov 20, 2017 at 12:10 PM

Projectile motion is something that a body undergoes when it is thrown in air. The path taken by the projectile motion is called trajectory. A bomb released from an aeroplane in level flight, bullet getting fired from gun, an athlete throws a javelin illustrates the trajectory motion.

alt text Trajectory formula is given by alt text

Where, y is the horizontal component, x is the vertical component, g= gravity value, v= initial velocity, θ = angle of inclination of the initial velocity from horizontal axis, alt text Where, Vo is the initial Velocity, sin θ is the y-axis vertical component , cos θ is the x-axis horizontal component.

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
1

Answer by JonPQ · Nov 20, 2017 at 05:20 PM

This works well with Vectors.. for motion. S = ut + .5 a t^2 where s= distance. u= starting velocity a = acceleration / gravity t = time

Use that, just for vertical motion, where U = vertical component velocity of the ball being fired up. S(distance) = - height above floor. a is gravity. re-arrange formula to get 't' t^2= (s-ut) / .5a t = sqr( (s-ut) / .5a) This will give you time the ball is in the air... (without drag) Its not trivial to take your ball move vector (without Y) to get final landing point. end point = start point + vectorMove(xz only).normalized * time;

Your problem.... is the drag. much harder to calculate with variable speed. Suggestion... do it more like wind... a small vector added to position every time slice. That way you can again calculate deviation in final position, based on that time you calculated. deviationDeltaVector (drag or wind, in xz planes only) * time. and add that into final landing position.

Have done this before in golf game, grenades, and hunting (bullets) tricky, but you can get something convincing using this method.

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 sachinkhanna786 · Dec 27, 2017 at 08:00 AM

You can extract files from cricket 07 using biggui to check this or can extract files from don bradman cricket 17.

,you can take clues from don bradman cricket 17 game.

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

76 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

Related Questions

How can I show trajectory of a bouncing ball OnCollisionEnter/OnCollisionExit? 0 Answers

Trajectory prediction with linear drag 1 Answer

2D Trajectory/Path Predictor 0 Answers

Trajectory prediction basketball 1 Answer

2D ball same bounce height on objects as on the ground 2 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