Comments and answers for "Unity3d find angle/direction of a Ray / Raycasthit"
http://answers.unity.com/questions/1232662/unity3d-find-angledirection-of-a-ray-raycasthit.html
The latest comments and answers for the question "Unity3d find angle/direction of a Ray / Raycasthit"Comment by Ssiroo on Ssiroo's answer
http://answers.unity.com/comments/1233183/view.html
Hey, that did the trick. Thank you very much for your help!Mon, 22 Aug 2016 19:04:12 GMTSsirooComment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/1233134/view.html
In the 3d case you would need to calculate the correct tangent. This can be done by using ["Vector3.ProjectOnPlane"][1] and projecting the direction vector between the two balls onto the plane with the hit normal as normal. You might want to take some extra care when the direction is in line with the hit normal. In this case it's a central collision, so the cue ball stops and the other moves in a straight line
If you also need the reflection off a wall it's basically the same as with two balls, just that the impulse that would drive the other ball (which is now the wall) is simply reflected back onto cue ball) So you simply apply both velocities to the ball but reverse the vector that goes "into the wall"
[1]: https://docs.unity3d.com/ScriptReference/Vector3.ProjectOnPlane.htmlMon, 22 Aug 2016 17:16:11 GMTBunny83Answer by Bunny83
http://answers.unity.com/answers/1233129/view.html
Well, the rules are pretty simple. The ball you hit moves along the hit normal and the ball that hits moves along the tangent of the hit point.
[Wikipedia ellastic collision][1] has this animated gif which should explain everything:
<a href="https://de.wikipedia.org/wiki/Datei:Elastischer_sto%C3%9F_2D.gif"><img src="https://upload.wikimedia.org/wikipedia/commons/2/2c/Elastischer_sto%C3%9F_2D.gif"></a>
So what you have to do is:
- get the normal vector of your collision
- calculate the tangent (in 2d simply rotate the normal 90°)
- Project the original velocity vector onto both normalized directions (normal, tangent)
- Apply the resulting vector as new velocity vectors for each ball.
This of course assumes that the two balls have the same mass.
This is how you calculate it manually. Keep in mind that the physics system might give you a different result due to some inaccuracies and rotations involved in the collision. Also keep in mind when you calculate it manually that it's possible to get a chain reaction of new collisions when more than 2 balls are involved. This might be difficult to simulate with a limited frame rate / certain step size.
For example a "split" of two balls with a third will result the wrong direction of the cueball if you process one collision at a time.
[1]: https://en.wikipedia.org/wiki/Elastic_collision#Two-dimensionalMon, 22 Aug 2016 17:09:29 GMTBunny83Comment by Ssiroo
http://answers.unity.com/comments/1233090/view.html
Bump. Sorry for the spam but I really need this.Mon, 22 Aug 2016 15:19:56 GMTSsiroo