x


iPhone ball roll problem

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 ^_^

more ▼

asked Jul 13 '10 at 05:34 PM

B3NN gravatar image

B3NN
21 2 2 7

If you don't want the ball to bounce at all you could set the y axis to zero in the update function.

Jul 13 '10 at 06:08 PM MikezNesh
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Turns out the that the walls used to enclose the ball were not thick enough to contain it.. Just a matter of increasing the thickness. :) This way, I don't have to restrict the ball to just the Y axis and don't need to slow down the fixedTimeStep.

This also allowed me to increase the balls movement speed enough to have the effect I wanted! Was a minor headache, but it's done now :) Thanks for the help above, also :)

more ▼

answered Jul 21 '10 at 12:37 AM

B3NN gravatar image

B3NN
21 2 2 7

As for making wall thick, you might want this instead: http://www.unifycommunity.com/wiki/index.php?title=DontGoThroughThings

Jan 28 '11 at 10:24 PM Cawas
(comments are locked)
10|3000 characters needed characters left

To prevent object's from going through each other, you could just decrease the fixedTimeStep in the physics settings (Edit->ProjectSettings->Physics).

more ▼

answered Jul 13 '10 at 06:55 PM

Daniel 6 gravatar image

Daniel 6
541 2 4 17

I did try that, however slowing down the fixedTimeStep just slowed down the entire game.. i really wanted the ball to move quickly.

Jul 21 '10 at 12:33 AM B3NN
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2000
x169
x140
x59

asked: Jul 13 '10 at 05:34 PM

Seen: 1702 times

Last Updated: Jul 13 '10 at 06:43 PM