Just a heads up, im a beginner trying to make a game thats a bit ambitious for my skill level so be easy on me.
Basically I have a tube of a certain length, a wall object at the back end, and a ball object. I want the ball to stick to the inside walls of the tunnel and move freely and bounce off the back wall and come back. Ive searched for a long time and the closest thing i could find that kinda worked was this:
public float wallGravity = -9.81f;
void OnCollisionStay(Collision col)
{
Vector3 n = Vector3.zero;
foreach (ContactPoint C in
col.contacts)
n += C.normal;
n.Normalize();
Physics.gravity = -n * wallGravity;
}
Not exactly sure how it works but it acts crazy and doesnt really work well. Also it sticks itself to the back wall when it hits instead of bouncing off (i have bouncy physics material on back wall). So basically im looking for suggestions on a different way to stick the ball to the tunnel but not the back wall. Ive heard raycasting would work, but i know jack about that. If thats the best course, ill gladly learn about it. Anything would be helpful!