How to make sphere 'stick' to inside of hollow cylinder
Hello all, I've searched far and wide and can't seem to find a solution to this. The idea is that the sphere is controlled by the player and they can 'roll' this around the inside of the cylinder to avoid oncoming obstacles. I've messed around with gravity (increasing, reversing etc) but at times this will make the ball float.
Is there anyway to make the two objects to always be touching one another?
Heres the code for moving my sphere: (FYI: 'path' is the cylinder)
private float forwardSpeed;
private Rigidbody rb;
private GameObject path;
// Use this for initialization
void Start () {
forwardSpeed = 5F;
Input.gyro.enabled = true;
rb = GetComponent<Rigidbody>();
path = GameObject.Find("EmptyCylinder");
}
// Update is called once per frame
void Update () {
float gyroControls = Input.acceleration.x * 10;
if (transform.position.y >= path.transform.position.y)
{
// allows the player to traverse entire cylinder by just moving left/right
gyroControls = gyroControls * -1;
}
Vector3 v = new Vector3(gyroControls, forwardSpeed);
rb.AddForce(v);
}
void LastUpdate()
{
// slowly increases speed
forwardSpeed += 0.001F;
}
}
EDIT: Unable to add picture of play area I guess I'm writing the markdown text incorrectly! It is however just a hollow cylinder with a ball inside! Thank you for any help of course!
Sorry to reply really late, but I just want to understand that you want a behavior where cylinder is a really big gameobject and the sphere can travel inside the cylinder?