views:

161

answers:

1

I'm making an iPhone game where the main actor is a ball that rolls depending on the device's accelerometer rotation.

I haven't started on this part of the coding yet, but I was wondering if you guys had a nice way of solving this:

I tried looking a little into chipmunk, and I noticed that bodies have the property v, which is a point containing x and y velocities.

I was thinking it'd be a bad idea to just do like:

playerBody->v = ccp(accelerometer.x * 5, playerBody->v.y);

because it'd just roll up of walls and stuff,

is there a better solution to do this?

A: 

Basically, in a perfectly elastic collision (no energy lost) with a wall, which I'm guessing is what you want, the component of the velocity that is normal (perpendicular) to the wall is reversed (inverted). The tangential components stay the same. For instance, if the wall is along the x-axis, then v_y = -v_y. I haven't used Chipmunk so I won't attempt to tell you the actual syntax for doing this.

Justin Peel