Rotating a Kinematic Body

Hey guys,

I am trying to do something very simple and am having issues. I have a Kinematic body that is cup shaped. I made this shape using 3 seperate polygons that are 1 physics body (none are concave). I then have a “dynamic” ball shaped object that sits in the cup. I am attempting to rotate the cup display object/physics body. I am viewing my app in physics “hybrid” mode, and I can “visually” see the Kinematic cup object rotating, however the actual body that is interacting with the ball seems to be staying in place…

Does anyone know why this might be happening? Thanks in advance

PS - I added drag functionallity to the cup and it drags around just fine and the ball inside the cup moves with it as it should, the issue seems to be with rotation… [import]uid: 19620 topic_id: 36186 reply_id: 336186[/import]

I found out that this strange behaviour is happening when I have my reference point of the display object set to anything other than the defaul (center)… Well that puts a damper on my project [import]uid: 19620 topic_id: 36186 reply_id: 143836[/import]

That’s correct, as mentioned here: http://developer.coronalabs.com/reference/index/physicsaddbody

“When you turn a display object into a physics object, the Physics engine owns the object and has its own rules about the object. Physics assumes the reference point of the object is the center of the object so object:setReferencePoint() may change the reference point from Corona’s Display Object point of view but not for the Physics engine. This affects collisions and how other physics bodies interact.”

But what you’re trying to accomplish should still be possible, I think. Happy to try to help if you have any code you can share about how you’ve set up your objects.

  • Andrew [import]uid: 109711 topic_id: 36186 reply_id: 143843[/import]

Thanks for the response! I missed that, that is good to know.

I assume that to rotate my physics body I need to do something like apply angular impulse perhaps?

Here is what I am trying to accomplish. I am helping my brother with a college project ( he does all the illustrations ). It is going to be a zombie ebook thing.

On this page a zombie has “brains” in his hand (which is shaped like a cup). The zombie has his mouth open, and I wanted to make it so that the zombies arm can be dragged down (and it pivots - rotates - around the zombies elbow ). When you let go I wanted to make the arm fling back up like a spring and launch the brains out of the hand and towards the zombies mouth. So the person using the app would be trying to get the brains in the zombies mouth.

So I thought it would be best to make the hand a physics “cup” shaped object, and the brains a dynamic object. Thus far the whole “springing” arm thing doesn’t seem to work well with launching the brains. Any ideas on the best way to do this? [import]uid: 19620 topic_id: 36186 reply_id: 143862[/import]

Hi there,

Yes, to rotate a physics body it’s best to apply an angular impulse or force, so that the physics engine “knows” about the rotation and can handle its effect on the object and other objects properly. Setting a physics body’s rotation property directly is permitted, but the physics simulation won’t be quite the same or look quite right in many cases.

My first thought on how to accomplish your idea would be to make the arm below the elbow, as well as the cup-like hand, one complex, dynamic physics body. You could make the elbow a static physics object. Then you could connect the two using a pivot joint. For the pivot joint, you could set the rotation limits so that the arm below the elbow can only rotate within a certain range. You could then also set the motor properties of the joint so that it will naturally try to rotate upwards, providing the springiness effect.

Hope this helps!

  • Andrew [import]uid: 109711 topic_id: 36186 reply_id: 143892[/import]

Thanks for your help thus far!
I am attempting to do as you suggested, but am stuck trying to impliment a motor. Do you have any experience adding a motor in your projects? I am setting the “motorSpeed” of my pivot joint and the zombies arm will not do anything no matter how high I put the motorSpeed… what am I doing wrong? [import]uid: 19620 topic_id: 36186 reply_id: 144229[/import]

Hi there,

I’ve tinkered with joint motors but haven’t used them extensively. For your situation I’d suggest two things: first, try making your cup-like hand a dynamic object rather than a kinematic object, and second, in addition to setting the motorSpeed of the joint, be sure to also set the maximumTorque to some very, very high value. If the combination of those two things doesn’t help, then I’d be happy to take a look at your code and see if we can figure out how to make it work.

  • Andrew [import]uid: 109711 topic_id: 36186 reply_id: 144235[/import]

Yea, not working out… corona sure makes doing physics things wonky sometimes.

I would be fine to email you my project, its all just a prototype so I don’t mind. Send me an email at rx-madjack@hotmail.com if you don’t mind and I can respond with it. [import]uid: 19620 topic_id: 36186 reply_id: 144237[/import]

I found out that this strange behaviour is happening when I have my reference point of the display object set to anything other than the defaul (center)… Well that puts a damper on my project [import]uid: 19620 topic_id: 36186 reply_id: 143836[/import]

That’s correct, as mentioned here: http://developer.coronalabs.com/reference/index/physicsaddbody

“When you turn a display object into a physics object, the Physics engine owns the object and has its own rules about the object. Physics assumes the reference point of the object is the center of the object so object:setReferencePoint() may change the reference point from Corona’s Display Object point of view but not for the Physics engine. This affects collisions and how other physics bodies interact.”

But what you’re trying to accomplish should still be possible, I think. Happy to try to help if you have any code you can share about how you’ve set up your objects.

  • Andrew [import]uid: 109711 topic_id: 36186 reply_id: 143843[/import]

Thanks for the response! I missed that, that is good to know.

I assume that to rotate my physics body I need to do something like apply angular impulse perhaps?

Here is what I am trying to accomplish. I am helping my brother with a college project ( he does all the illustrations ). It is going to be a zombie ebook thing.

On this page a zombie has “brains” in his hand (which is shaped like a cup). The zombie has his mouth open, and I wanted to make it so that the zombies arm can be dragged down (and it pivots - rotates - around the zombies elbow ). When you let go I wanted to make the arm fling back up like a spring and launch the brains out of the hand and towards the zombies mouth. So the person using the app would be trying to get the brains in the zombies mouth.

So I thought it would be best to make the hand a physics “cup” shaped object, and the brains a dynamic object. Thus far the whole “springing” arm thing doesn’t seem to work well with launching the brains. Any ideas on the best way to do this? [import]uid: 19620 topic_id: 36186 reply_id: 143862[/import]

Hi there,

Yes, to rotate a physics body it’s best to apply an angular impulse or force, so that the physics engine “knows” about the rotation and can handle its effect on the object and other objects properly. Setting a physics body’s rotation property directly is permitted, but the physics simulation won’t be quite the same or look quite right in many cases.

My first thought on how to accomplish your idea would be to make the arm below the elbow, as well as the cup-like hand, one complex, dynamic physics body. You could make the elbow a static physics object. Then you could connect the two using a pivot joint. For the pivot joint, you could set the rotation limits so that the arm below the elbow can only rotate within a certain range. You could then also set the motor properties of the joint so that it will naturally try to rotate upwards, providing the springiness effect.

Hope this helps!

  • Andrew [import]uid: 109711 topic_id: 36186 reply_id: 143892[/import]

Thanks for your help thus far!
I am attempting to do as you suggested, but am stuck trying to impliment a motor. Do you have any experience adding a motor in your projects? I am setting the “motorSpeed” of my pivot joint and the zombies arm will not do anything no matter how high I put the motorSpeed… what am I doing wrong? [import]uid: 19620 topic_id: 36186 reply_id: 144229[/import]

Hi there,

I’ve tinkered with joint motors but haven’t used them extensively. For your situation I’d suggest two things: first, try making your cup-like hand a dynamic object rather than a kinematic object, and second, in addition to setting the motorSpeed of the joint, be sure to also set the maximumTorque to some very, very high value. If the combination of those two things doesn’t help, then I’d be happy to take a look at your code and see if we can figure out how to make it work.

  • Andrew [import]uid: 109711 topic_id: 36186 reply_id: 144235[/import]

Yea, not working out… corona sure makes doing physics things wonky sometimes.

I would be fine to email you my project, its all just a prototype so I don’t mind. Send me an email at rx-madjack@hotmail.com if you don’t mind and I can respond with it. [import]uid: 19620 topic_id: 36186 reply_id: 144237[/import]

I found out that this strange behaviour is happening when I have my reference point of the display object set to anything other than the defaul (center)… Well that puts a damper on my project [import]uid: 19620 topic_id: 36186 reply_id: 143836[/import]

That’s correct, as mentioned here: http://developer.coronalabs.com/reference/index/physicsaddbody

“When you turn a display object into a physics object, the Physics engine owns the object and has its own rules about the object. Physics assumes the reference point of the object is the center of the object so object:setReferencePoint() may change the reference point from Corona’s Display Object point of view but not for the Physics engine. This affects collisions and how other physics bodies interact.”

But what you’re trying to accomplish should still be possible, I think. Happy to try to help if you have any code you can share about how you’ve set up your objects.

  • Andrew [import]uid: 109711 topic_id: 36186 reply_id: 143843[/import]

Thanks for the response! I missed that, that is good to know.

I assume that to rotate my physics body I need to do something like apply angular impulse perhaps?

Here is what I am trying to accomplish. I am helping my brother with a college project ( he does all the illustrations ). It is going to be a zombie ebook thing.

On this page a zombie has “brains” in his hand (which is shaped like a cup). The zombie has his mouth open, and I wanted to make it so that the zombies arm can be dragged down (and it pivots - rotates - around the zombies elbow ). When you let go I wanted to make the arm fling back up like a spring and launch the brains out of the hand and towards the zombies mouth. So the person using the app would be trying to get the brains in the zombies mouth.

So I thought it would be best to make the hand a physics “cup” shaped object, and the brains a dynamic object. Thus far the whole “springing” arm thing doesn’t seem to work well with launching the brains. Any ideas on the best way to do this? [import]uid: 19620 topic_id: 36186 reply_id: 143862[/import]

Hi there,

Yes, to rotate a physics body it’s best to apply an angular impulse or force, so that the physics engine “knows” about the rotation and can handle its effect on the object and other objects properly. Setting a physics body’s rotation property directly is permitted, but the physics simulation won’t be quite the same or look quite right in many cases.

My first thought on how to accomplish your idea would be to make the arm below the elbow, as well as the cup-like hand, one complex, dynamic physics body. You could make the elbow a static physics object. Then you could connect the two using a pivot joint. For the pivot joint, you could set the rotation limits so that the arm below the elbow can only rotate within a certain range. You could then also set the motor properties of the joint so that it will naturally try to rotate upwards, providing the springiness effect.

Hope this helps!

  • Andrew [import]uid: 109711 topic_id: 36186 reply_id: 143892[/import]

Thanks for your help thus far!
I am attempting to do as you suggested, but am stuck trying to impliment a motor. Do you have any experience adding a motor in your projects? I am setting the “motorSpeed” of my pivot joint and the zombies arm will not do anything no matter how high I put the motorSpeed… what am I doing wrong? [import]uid: 19620 topic_id: 36186 reply_id: 144229[/import]