problems with physics

Originally, I had an image of a windmill and an image of a windmill blade.  I started by adding 4 blades and setting their rotation, then setting their reference point, and then rotating them around a circle in the center of my windmill.  That worked great!  Then I added physics and it all fell to pieces as the physical location of the physics object wasn’t in the place that the rotation was.  Basically my golf ball wouldn’t bounce off the blades.  on IRC someone named Goosh suggested using 2 squares and having them overlap in the center, but that doesn’t work for me for a very good reason.  I plan on blowing up individual blades, and the center will then change.  
 
Here’s what I’ve got.  I can’t get the windmill blades to spin, I have no idea what I’m doing wrong.  I can’t find a single example on how to do this using corona.  Simplest example possible (assume all variables are declared if I left out a local here or there)

myCircle = display.newCircle(screenW / 2, 132 , 10) physics.addBody(myCircle, "kinematic", {friction=0.1, radius=10})   local blade = display.newImage("windmill\_blade.png") blade.x = screenW / 2  - imageWidth / 2 blade.y = 130 physics.addBody(blade, "kinematic", {friction=0.1, density=0.8}) local joint = physics.newJoint( "pivot", blade, myCircle, 132, 130)

 
I have tried these:

blade:applyTorque(5000)  -- and many other numbers myCircle:applyTorque(5000) -- and many other numbers joint:applyTorque(5000) -- this blows up?

I’m just not sure what I’m doing wrong.  I’ve tried weld joints, I’ve tried static bodies, I’ve tried dynamic bodies, although I don’t want them affected by gravity, nor do I want them to move when the golf ball hits them.  I’ve got no friggin idea what the right way to do this is, and in the examples I see nothing related to this.

Making both the blade and the circle dynamic made some really interesting things happen, but not quite what i was looking for as I don’t want the ball to move (it’s just an anchor)

Hi Jason,

I can point out a few things which should help…

You should attach the blades to the hub using weld joints. Remember that a weld joint attaches two bodies at a single point in “world coordinates”, like a rivet pounded through the two bodies. So, you should overlap the blades slightly onto the hub, and weld them at that cross-over point.

Once you have the body created properly, it’s time to set it in motion. Dynamic bodies are the only type which respond to force (like gravity) or force reactions (like something colliding with it). However, if you don’t want the ball to “move” these, you’re better off doing kinematic. You can individually turn off gravity on dynamic objects by setting their gravityScale to 0, but the ball will still potentially move the object unless the density of the windmill is really high.

Kinematic is the better solution, but you can’t apply “force” reactions to these. That’s why your kinematic body was not moving with such commands as “applyTorque()”. Instead, you’ll need to set the constant rotation using “object.angularVelocity”:

http://docs.coronalabs.com/api/type/Body/angularVelocity.html

Set this angular velocity on the HUB, not the blades. The blades, being welded to the hub, will turn along with it.

Hope this helps!

Brent Sorrentino

I appreciate the explanation. It doesn’t seem to work though. If the blades are kinematic, and the hub is also kinematic, then the blades do not turn. If I make the blades dynamic, then the blades turn.

I also have static wall boundaries for my golf ball, and when the windmill blades encounter those walls, they are dragged awkwardly along the edge. Is there a way to make the windmill blades ignore the static boundaries? I mean, I can fix my display problems by changing the placement or visual angle of my windmill, but I’m just trying to explore my options, this is just the first board I’m writing.

Hi Jason,

Yes, I just realized, the weld joints must be applying force to the blades, so they need to be dynamic. Can you test making the entire structure dynamic, and set the gravityScale to 0 so it doesn’t fall under gravity?

http://docs.coronalabs.com/api/type/Body/gravityScale.html

For the walls issue, you can make any body “ignore” another body by setting up collision filters. There’s a walkthrough that I put together sometime ago on this (it’s older, but it still works exactly as described and nothing has changed internally):

http://forums.coronalabs.com/topic/2128-collision-filters-helper-chart/

Brent

That’s an amazing article, thanks!

Hi Jason,

I can point out a few things which should help…

You should attach the blades to the hub using weld joints. Remember that a weld joint attaches two bodies at a single point in “world coordinates”, like a rivet pounded through the two bodies. So, you should overlap the blades slightly onto the hub, and weld them at that cross-over point.

Once you have the body created properly, it’s time to set it in motion. Dynamic bodies are the only type which respond to force (like gravity) or force reactions (like something colliding with it). However, if you don’t want the ball to “move” these, you’re better off doing kinematic. You can individually turn off gravity on dynamic objects by setting their gravityScale to 0, but the ball will still potentially move the object unless the density of the windmill is really high.

Kinematic is the better solution, but you can’t apply “force” reactions to these. That’s why your kinematic body was not moving with such commands as “applyTorque()”. Instead, you’ll need to set the constant rotation using “object.angularVelocity”:

http://docs.coronalabs.com/api/type/Body/angularVelocity.html

Set this angular velocity on the HUB, not the blades. The blades, being welded to the hub, will turn along with it.

Hope this helps!

Brent Sorrentino

I appreciate the explanation. It doesn’t seem to work though. If the blades are kinematic, and the hub is also kinematic, then the blades do not turn. If I make the blades dynamic, then the blades turn.

I also have static wall boundaries for my golf ball, and when the windmill blades encounter those walls, they are dragged awkwardly along the edge. Is there a way to make the windmill blades ignore the static boundaries? I mean, I can fix my display problems by changing the placement or visual angle of my windmill, but I’m just trying to explore my options, this is just the first board I’m writing.

Hi Jason,

Yes, I just realized, the weld joints must be applying force to the blades, so they need to be dynamic. Can you test making the entire structure dynamic, and set the gravityScale to 0 so it doesn’t fall under gravity?

http://docs.coronalabs.com/api/type/Body/gravityScale.html

For the walls issue, you can make any body “ignore” another body by setting up collision filters. There’s a walkthrough that I put together sometime ago on this (it’s older, but it still works exactly as described and nothing has changed internally):

http://forums.coronalabs.com/topic/2128-collision-filters-helper-chart/

Brent

That’s an amazing article, thanks!