- Home /
Push Rigidbody ball around a loop de loop?
I'm trying to get a rigidbody ball character to go around a roller coaster styled loop using only physics. I've tried the downforce method with -transform.up gravity mass but the character simply stops when the loop becomes too steep (around 90 degrees). I've got collision data via a downwards raycast and visual debugging shows the ray aligning to the normal of the loop, I'm wondering what would be the best way to use this data to apply the appropriate force. I've also tried adding force with the raycast hit - the player position but that yielded the same result. If anyone could help me on this I would greatly appreciate it, I've yet to see anybody achieve this without a spline path.
How do you find the current "down"? In other words, how do you know which direction to raycast to get the loop normal? The ball's local down, is just going to spin like mad, pointing wherever.
Seems the trick is to take the center of the loop, $$anonymous$$us your current position (and then the normal of the "real" curved loop is the opposite.)
Answer by Loius · Apr 12, 2013 at 05:47 AM
The Vector3.Cross( +/- player.right, surface.normal ) will give you either the ball's forward or backward relative to the slope depending on whether you send + or - player.right. That is, you'll get the direction the ball should be moving at that point in the loop.
If you rotate that direction slightly towards the ramp (away from surface normal), you can apply force along that direction and keep the ball pinned to the surface and moving forward.
Such is the hope, at least. :)
Edit: Oh, and if the ball is spinning wildly and has no consistent .right, you might can use the loop object's .right instead.
But how would you rotate that direction vector "slightly"?
Your answer
![](https://koobas.hobune.stream/wayback/20220613100145im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rigidbody bowls/baskets - is there a better way? 0 Answers
Object Flies into Air Upon Collision, or goes through hill depending on isKinematic settings 1 Answer
Invalid AABB Error on collision :( 1 Answer
RigidBody immediately stops after AddForce 1 Answer
How to setup character Collisions? 2 Answers