I'm using the Roll-A-Ball script to have a ball roll around a small area and I am having two problems:
1) The ball is rolling around in a box made of flattened cubes. All but the bottom has mesh render removed so they can't be seen. Is there any reason why, when the tilt angle is too great, the ball gains enough momentum to launch out of this box?
2) I want to change the existing script so that when tilted, the ball has a set speed. I need the player to be able to switch directions quickly and this seems impossible as the physics (or accelerometer?) are causing the ball to just slow down and then eventually speed up again when tilt direction is changed.
I think if I could fix problem 1) then I could just increase force enough so that changing direction wouldn't take so long...
Here is the code example:
function Start()
{
iPhoneSettings.screenOrientation = iPhoneScreenOrientation.Landscape;
}
function FixedUpdate ()
{
var dir : Vector3 = Vector3.zero;
dir.x = -iPhoneInput.acceleration.y;
dir.z = iPhoneInput.acceleration.x;
if (dir.sqrMagnitude > 1)
dir.Normalize();
rigidbody.AddForce(dir * force);
}
This is looking all funny on my screen, I think I've pressed something wrong trying to copy the code in..
Any help would be greatly appreciated ^_^