Rotating Hammer

Official forum for the Chipmunk2D Physics Library.
Post Reply
cmkilger
Posts: 3
Joined: Wed Jan 14, 2009 12:02 am
Contact:

Rotating Hammer

Post by cmkilger »

I'm trying to create an object that acts like a rotating hammer. It should rotate at the end of the handle, be slow to go up, but then quickly come down and hit anything in the way. I tried creating two bodies, one for the handle and the other for the head, and pinning them together with a joint, but the joint acts more like a spring. If I use one body it rotates uniformly; it isn't any slower going up than going down. How should I go about this?

In the screenshot you can kind of see what I'm going for, I just want the yellow joint to have zero length.
Screen shot 2009-11-25 at 12.57.53 PM.png
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Rotating Hammer

Post by slembcke »

You will want to put them on the same body for sure. It's a solid object, and joints don't make for good solid objects.

Why should it rotate slower going up than down? Is it being winched up slowly then let to fall under gravity? How are you controlling the rotation now?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
mobilebros
Posts: 90
Joined: Tue Aug 04, 2009 9:53 am
Contact:

Re: Rotating Hammer

Post by mobilebros »

I think he might be saying that he prefers the handle to be lighter than the head, therefore requiring two bodies... possibly? What kind of joint are you using? You should probably use two pivot joints to connect the head to the handle to get it steady.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Rotating Hammer

Post by slembcke »

Doesn't matter if you want the handle heavier than the head if they are a solid object. Placing the center of gravity at the correct place and calculating the moment of inertia correctly is all you really need to know. Calculating the center of gravity is as simple as a weighted average, and calculating the moment of inertia just becomes a matter of calculating offsets to give the primitive moment calculation functions.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
cmkilger
Posts: 3
Joined: Wed Jan 14, 2009 12:02 am
Contact:

Re: Rotating Hammer

Post by cmkilger »

I figured it may need to be a single body. I want it to go slowly up and then faster down to simulate a motor that would be fighting against gravity, peak, and then be moving with gravity. I tried using a simple motor on a single body, but it seems like the motor rotates it around the center of gravity, which should be at the head of the hammer. I also tried rotating it by setting the torque, similar to the Moonbuggy demo.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Rotating Hammer

Post by slembcke »

cmkilger wrote:I tried using a simple motor on a single body, but it seems like the motor rotates it around the center of gravity, which should be at the head of the hammer.
The simple motor simply applies rotation period. So yes, it will cause it to rotate around the CoG. You'll need to add a pivot joint if you want it to rotate around a separate point.

Secondly, the default value for the a simple motor's maximum torque (constraint.maxForce) is infinite, so it will basically always rotate at the given speed. Experiment to find a value that can just barely lift the hammer to get the behaviour that you want.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
cmkilger
Posts: 3
Joined: Wed Jan 14, 2009 12:02 am
Contact:

Re: Rotating Hammer

Post by cmkilger »

slembcke wrote:The simple motor simply applies rotation period. So yes, it will cause it to rotate around the CoG. You'll need to add a pivot joint if you want it to rotate around a separate point.

Secondly, the default value for the a simple motor's maximum torque (constraint.maxForce) is infinite, so it will basically always rotate at the given speed. Experiment to find a value that can just barely lift the hammer to get the behaviour that you want.
That was exactly what I needed. Thanks!
Post Reply

Who is online

Users browsing this forum: Metager [Bot] and 30 guests