开发者

Chipmunk physics: Velocity question

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 velocit开发者_开发知识库ies.

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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜