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 Glenno · May 11, 2011 at 02:03 PM · raycasthitnormalreflectphysicsmaterial

rigidBody is heading to a slightly different angle to where im calculating it would be using Reflect

Hi,

I have a (maybe noob) question... (In JS btw)

I have a sphere collider(with a moveable rigidBody attached) hitting the flat edge of a box collider(with IsKinematic rigidBody attached).

ShotDirection is a unit direction vector, so therefore, so should be whiteBallFollowOnDir.

I am calculating the RayCastHit with:

sphereCastDidCollide = Physics.SphereCast(whiteBall.transform.position, whiteBallRadius, shotDirection, hit, 100, layerMask);

I take the hit.point, then use the hit.normal to get the opposite(reflected) direction vector that would happen had shotDirection collided at hit.point (NB:Is this basic vectors assumption correct?)

whiteBallFollowOnDir = Vector3.Reflect(shotDirection, hit.normal);

I also calculate a reference point along the hit.normal for where the white ball would be when it collides with the cushion, with:

refPositionFromNormal = hit.point + (hit.normal * whiteBallRadius);

I am calculating all these, in order to draw some guide lines on a pool game, that would give a rough(short line) indication of which direction the white ball will bounce off too.

In order to draw these lines, I use a lineRender, I set point 0 of the lineRender to be refPositionFromNormal, and point 1 to be that whiteBallFollowOnDir vector I have calculated previously, multiplied by an arbitrary length.

whiteBallFollowOnVector = whiteBallFollowOnDir * 10;

directionIndicatorLineRender.SetPosition(0,refPositionFromNormal); directionIndicatorLineRender.SetPosition(1,refPositionFromNormal+whiteBallFollowOnVector);

My question is.. does everything I am doing look right? As the whiteBallFollowOnVector lineRender is ever so close to the actual direction the ball bounces off to, but is just slightly out(shallower).

Is my maths correct and there something else I should be looking for. eg. would AngularDrag cause something like that(its set to 0 btw). Static friction of the ball collider/cushion colliders? drag of the table? air friction? (all of these are set to 0).

The only settings that arent 0 on these 2 colliders and Physics Materials, is: Cushion Physics Material, Bounciness = 0.804. Ball Physics Material, Bounciness = 0.98.

These are set to these values for the 'feel' of the game mechanics. But they shouldnt be affecting the simple vector theory should they?

I'm just wondering what else I could look into(providing theres nothing wrong with my maths/theory).

Thanks in advance, Glenno

p.s. sorry, that turned out longer that i'd hoped.

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
2
Best Answer

Answer by hellcats · May 11, 2011 at 02:40 PM

The "bounciness" is probably the problem. It is the amount of energy conserved by the bounce, so a value < 1 loses energy. If it was 0 then the sphere wouldn't bounce at all and would just slide along the plane of contact.

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 Glenno · May 11, 2011 at 04:09 PM 0
Share

Yep, thats it.. setting the bounciness to 1, makes my calculations right, thanks.. shouldve just set it to 1 to test to begin with, but i didnt think(for some reason) that it would change simple vector maths. duh! But now i have asked another question...If youre keen ;) http://answers.unity3d.com/questions/58305/anyone-know-the-maths-to-take-into-account-bounciness-when-calculating-trajectori

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

No one has followed this question yet.

Related Questions

What is a RaycastHit normal? 1 Answer

Why are RaycastHit surface normals of corners not interpolated or otherwise correct? 1 Answer

How to get Vector3.Reflect to make any number of reflections? 0 Answers

RaycastHit.normal Problem 1 Answer

Rotating a character relative to the ground's rotation 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