move sphere in tunnel

basically i want the ball to move in the round tunnel by applying force in z direction … camera follows the sphere … all works fine but when there is turn in the tunnel say right turn the ball is still moving in z direction

now , how to make sure that ball also rotates right when there is right turn in the tunnel … ? ?

have search for it everywhere but have not found the solution yet … :frowning:

any suggestion would be helpful … thanks in advance .!

rigidbody is attached to sphere and moving the sphere using rigidbody.velocity() and applying the velocity in z direction .

don't use rigidbody.velocity. apple forces. see 100s of questions on here about it, also unityGEMS.com for articles note that a "ball in a tunnel" is a very, very advanced challenge - there are many ways to do it and it depends hugely on the specifics of your game. to get more detailed help you'll absolutely need to include a screenshot showing your rig !

That's about the same problem as a racing game. The track twists, any child can point the exact "forward" on any section, but how does the game know that? There are some threads here on racing tracks. They often involve directions between way-points. Once you can find "track forward," you can push that way (velocity works, but many people find AddForce simpler to use.) The same math should also find "Track left/right."

this is how it looks when sphere moves forward .. [10611-simplemove.jpg|10611] this is how it looks there is turn in tunnel .. [10612-turn.jpg|10612] is there any way i could solve this problem or any thread realted to this .. ?

Actually The problem is with the direction of the ball. The tunnel is not always straight . It Bends at certain places in world. Now the question is How I can figure out the direction in which the ball needs to be given force. The whole tunnel is a single object . And the ball moves inside it with force or velocity. Main camera has smoothfollow script following the sphere.

1 Answer

1

It’s incredibly difficult o roll a ball correctly.

Furthermore, it is spectacularly difficult to roll a ball correctly in a curved container.

You’ll need to fully experiment with adding force at a position

(try near the global top of the object … just as you would in real life)

also experiment with adding torque

What Fafase says about checkpoints is correct.

You should be using check points which exist every 1 to 2 meters away (I’m thinking your ball is about 20 cm in size.)

If you’re not familar with using checkpoints, “check” answers here. It is tricky to “understand” which way is continuing forward. You have to check them off as you go and find the next one that is not checked off, then it “must be” in the direction you want to go. Anyway that’s all a minor issue.

(BTW … how big is your ball exactly, in real world units? And what mass? (KG) And is it metallic, or bouncy?)

There is no definitive answer to this problem, you must really master using “add force at point” and “adding torque”. You’ll need to do plenty experimentation to find a good result, probably combining those two.

THink about how you’d do it with your hand. You’d sort of “roll” the ball with a slightly upwards gesture where our hand touches.