physics issue when applying force to a body after setting a shape to it.

Hi, 

this is my code and it was working before I give shape to the object : [lua]jet = display.newImageRect(“jet.png”, 70, 37)

jet.x = screenLeft - 65; jet.y = screenTop+100;
screenGroup:insert(jet)
physics.addBody(jet, “dynamic”, {density = 2,friction = 0.1, isSensor = false,
shape =
{27-50, 35-20, 19-50, 30-20, 20-50, 7-20, 39-50, 6-20, 66-50, 11-20, 77-50, 23-20 } })

function activateJets(self,event)

    self:applyForce(0, -1.4, self.x, self.y)

end

function touchScreen(event)
if event.phase == “began” then
if event.x < rightMarg-150 then
print(“yoho”)
jet.enterFrame = activateJets
Runtime:addEventListener(“enterFrame”, jet)
end
end
if event.phase == “ended” then
Runtime:removeEventListener(“enterFrame”, jet)
end
end
 

Runtime:addEventListener(“touch”, touchScreen)[/lua]

how can I fix this ?

it’s supposed that the jet will get force to fly, but after adding the shape, it’s failing to get any force.

before the shape the density = 0, but after that, it acts weird if i set it to ‘0’ so I set to 2.

Hey Hammond,

It looks like some of the energy may be spinning the jet.  If you crank up the applyForce’s Y value to -100 in line #10 , you should see what I mean.

you can use :

[lua]

jet.isFixedRotation = true

[/lua]

in line 7’s place to prevent the jet from spinning, if you want.

Also, are the shape’s coordinates supposed to have dashes in them?  Is that in -line math?   I don’t have your graphic, but the outline kinda reminds me of a side view of a B-2

The reason why you are seeing different behavior is that adding a shape affects the size of the object, and the weight of the object is determined by its size (area) and its density. So to get the behavior you want, you need to tweak the density of the object and/or the force you are applying, until you get the behavior you want.

And yes, your density should be >0 or the engine will be very confused about the weight of the object :slight_smile:

@r.delia

I tried what you said and the object is spinning and nothing fixed, here’s a picture of the object and the shape:

6da6dd35deaea26.png

is it something that can be fixed ?


@memo

I followed @r.della and made forceY -100, and followed you and tried many values if densities so the jet fly good but never stops spinning !

Hi @hammod-930,

I didn’t “draw out” your shape coordinates, but have you confirmed that the points are declared in clockwise order? If they’re not, this will result in many problems down the road (even if the body might look correct in the hybrid view).

Also, did you set .isFixedRotation after you make the body physical? This is a fairly common mistake for users who don’t use physics a lot… you need to apply those type of properties after the body is made physical, otherwise Corona will just treat it like any other custom property and not a physics-related one.

Take care,

Brent

thank you @Brent, that was the mistake.

Hey Hammond,

It looks like some of the energy may be spinning the jet.  If you crank up the applyForce’s Y value to -100 in line #10 , you should see what I mean.

you can use :

[lua]

jet.isFixedRotation = true

[/lua]

in line 7’s place to prevent the jet from spinning, if you want.

Also, are the shape’s coordinates supposed to have dashes in them?  Is that in -line math?   I don’t have your graphic, but the outline kinda reminds me of a side view of a B-2

The reason why you are seeing different behavior is that adding a shape affects the size of the object, and the weight of the object is determined by its size (area) and its density. So to get the behavior you want, you need to tweak the density of the object and/or the force you are applying, until you get the behavior you want.

And yes, your density should be >0 or the engine will be very confused about the weight of the object :slight_smile:

@r.delia

I tried what you said and the object is spinning and nothing fixed, here’s a picture of the object and the shape:

6da6dd35deaea26.png

is it something that can be fixed ?


@memo

I followed @r.della and made forceY -100, and followed you and tried many values if densities so the jet fly good but never stops spinning !

Hi @hammod-930,

I didn’t “draw out” your shape coordinates, but have you confirmed that the points are declared in clockwise order? If they’re not, this will result in many problems down the road (even if the body might look correct in the hybrid view).

Also, did you set .isFixedRotation after you make the body physical? This is a fairly common mistake for users who don’t use physics a lot… you need to apply those type of properties after the body is made physical, otherwise Corona will just treat it like any other custom property and not a physics-related one.

Take care,

Brent

thank you @Brent, that was the mistake.