Manual body/shape rotation

Official forum for the Chipmunk2D Physics Library.
Post Reply
crmagicxxx
Posts: 3
Joined: Wed Apr 22, 2009 4:09 pm
Contact:

Manual body/shape rotation

Post by crmagicxxx »

Hello everybody...

I am experimenting with Chipmunk on iPhone and I came to something I can't solve by myself :oops: (and first, sorry if you find my English confusing, I am just a little better in English than Chipmunk :roll: )

As you can see in my attached image, I am trying to rotate body/shape based on finger input. As finger moves up or down the arrow area, body on the right rotates right or left. Rotation angle is calculated based on distance finger moved between two steps. I am doing that by manually changing the shape->a property, which nicely rotates the body, but I have problems having other objects to correspond to such rotations properly (in this case, the ball). As you can see, the ball with gravity has problems to respond to shape rotations in time, so it always "fall" into rotating shapes until rotations stop.

I've tried with bodies with INFINITIVE mass/impulse and static shapes, also tried with active bodies/shapes pinned by joint in the center but I always get same results. Tried with small angular steps like shape->a += 0.01f but ball just keeps falling into rotating shapes. With smaller angles falling is lesser than with larger angles of course, but for rotation to be smooth and appropriate for finger movement, angle must be changed proportionally.

I know the problem is that my rotating objects change their position/velocity too much for ball to pick it up in time, but there have to be some solution I can't figure out.

I've also tried with shape->w property, which gives better results because I suppose it's behavior is more predictive to Chipmunk than raw angle change, but I can't get proper rotation results based on finger movement with that option...

All in all, what I try here to accomplish is for example this:

If finger moved up 40 pixels between time step, I want to rotate my object for example 1.5 radians and ball to respond properly to that.

Thank you in advance and I hope I was clear in my explanations.

Regards
crmagicxxx
Posts: 3
Joined: Wed Apr 22, 2009 4:09 pm
Contact:

Re: Manual body/shape rotation

Post by crmagicxxx »

bump :roll:
PeskyJ
Posts: 19
Joined: Fri Apr 24, 2009 4:24 pm
Location: Reading, UK
Contact:

Re: Manual body/shape rotation

Post by PeskyJ »

Read the docs, you're not supposed to set the angle directly, instead, apply a torque (the ->w value). You should play with this more until you get it right, applying the torque to force the engine to make the rotation might not be as predictable, which is why you will need to keep testing and adjusting how much you set and how to remove the torque when the touch ends.
Games games games... I love games. Check out my games: [url]http://www.tinyplay.com/games.html[/url]
crmagicxxx
Posts: 3
Joined: Wed Apr 22, 2009 4:09 pm
Contact:

Re: Manual body/shape rotation

Post by crmagicxxx »

PeskyJ wrote:Read the docs, you're not supposed to set the angle directly, instead, apply a torque (the ->w value). You should play with this more until you get it right, applying the torque to force the engine to make the rotation might not be as predictable, which is why you will need to keep testing and adjusting how much you set and how to remove the torque when the touch ends.
Are you talking about torque (->t) or angular velocity (->w)?

Thanx
PeskyJ
Posts: 19
Joined: Fri Apr 24, 2009 4:24 pm
Location: Reading, UK
Contact:

Re: Manual body/shape rotation

Post by PeskyJ »

Yes, sorry, I meant ->t for torque.
Set the torque based on the value of w. For example you want it to spin at a certain speed, so apply a high torque to accelerate it up until w gets high enough then reduce t. When you no longer want it to spin, us t to dampen the rotation by setting it in the opposite direction to w.
Games games games... I love games. Check out my games: [url]http://www.tinyplay.com/games.html[/url]
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests