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
1
Question by JeffBert · May 04, 2017 at 01:34 PM · physics2dprojectilevector2bouncinessphysicsmaterial

Predicting projectile path after bouncing off Physics Material 2D

I have a projection line for my projectiles. The projection line is supposed to show where my projectiles will go even after bouncing off of colliders that have a physics material 2D.

I calculate the reflection from the incoming velocity and multiply it by the material's bounciness to get my bounce velocity.

The line works as expected as long as my material has a bounciness of 1. If I set the bounciness to anything between 0 and 1, the projection line "undershoots" the projectile. It seems that the physics material is adding a little more to the bounce.

alt text

bouncinessproblem.jpg (127.8 kB)
Comment
Add comment · Show 4
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 FortisVenaliter · May 04, 2017 at 08:06 PM 0
Share

Are you taking into account the bounceCombine variable of the physicsmaterial? Whatever it's set to, you'll also need to calculate to get the correct value.

avatar image JeffBert FortisVenaliter · May 04, 2017 at 08:31 PM 0
Share

I'm using the 2D Physics $$anonymous$$aterial which is more limited than the normal Physics$$anonymous$$aterial (no bounceCombine). I read somewhere that the physicsmaterial2d might use the multiply bounceCombine though.

$$anonymous$$y projectile's Physics $$anonymous$$aterial has 0 bounciness and 0 friction and only my platforms vary their bounciness. If my platform has a bounciness of 1 everything works correctly. It's when I changed the platform bounciness to a lower value (0 to 1) that my projectile line will incorrectly predict the projectile's path (undershooting it).

avatar image FortisVenaliter JeffBert · May 04, 2017 at 08:36 PM 0
Share

Hmmm, yeah, the docs don't really specify. But if the projectile's bounciness is always zero, then it must be maximum, since everything else would return at most 0.5.

avatar image Bunny83 FortisVenaliter · May 05, 2017 at 01:00 PM 1
Share

Box2d basically used "$$anonymous$$aximum" as combine mode. $$anonymous$$ultiply wouldn't make any sense for bounce, it only makes sense for friction.

For more information on how Box2d handles friction and bounce (restitution), see the Box2d manual chapter "Fixtures" and scroll down one page to "Friction" and "Restitution".

1 Reply

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

Answer by Bunny83 · May 05, 2017 at 12:49 PM

Well, i don't know how Box2d actually takes the bounce (or "restitution" as it's called internally) into account, but i'm pretty sure that you must only multiply the reflected part by the bounce value and not the whole velocity. Imagine an almost vertical wall. If the wall as well as the ball has a bounce value of "0", no bounce should happen at all. If the ball got shoot downwards at the wall, you don't want to bounce off the wall, but you want to maintain the downward motion. If you multiply the whole velocity by "0" it would make the object to completely stop, no matter at which angle you hit the wall.

So you need to split the velocity into the normal part and the tangent part. The normal part is reflected (inversed) and multiplied by the bounce value. The tangent part should stay the same.

So you should first project the velocity onto the normal to get the "normal part". Then you can subtract the normal part from the original velocity to get the tangent part. Then just inverse the normal and multiply by bounce and finally combine the two together.

Also keep in mind that Box2d uses the larger bounce value of the two materials involved.

This should work:

 Vector3 n = Vector3.Project(vIn, hitNormal);
 Vector3 t = vIn - n;
 return t - n * GetBounciness();
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 JeffBert · May 05, 2017 at 01:51 PM 0
Share

This explanation helped fix some other physics problems I was facing . Exactly what I was looking for. Thank you.

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

68 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

Related Questions

Shoot Projectile on the direction of where the gun is facing 1 Answer

PhysicsMaterial2D and bounciness: Getting weird angles when hitting box collider edges 2 Answers

the projectile reflects 1 time only when it hits something, pls help! 1 Answer

vector2.zero dont work in my code. 2 Answers

PhysicsMaterial2D bounces back in a strange angle when increasing bounciness 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