force not being applied to shaped object

Hey all! I’m new on this forum, and haven’t been coding lua for more then a week. Up till now i haven’t hit any major problems, but i’m at a loss on this one:

I currently have this code to add a previously defined player object to the physics engine:

local playerCollisionFilter = { categoryBits = 1, maskBits = 6 } local playerBodyElement = { filter=playerCollisionFilter} physics.addBody ( player, "dynamic", playerBodyElement )

When the player is touching the device, every frame this function is applied to the player:
player:applyForce( boostx, boosty, player.x, player.y )[/code]So far it works fine. The problem arises when i want some better collisions then using a rectangle surrounding my player sprite. I change the first part of the code above to this:[code]local playerCollisionFilter = { categoryBits = 1, maskBits = 6 }local playerShape = {0,-30,-30,15,30,15}local playerBodyElement = { filter=playerCollisionFilter, shape = playerShape} physics.addBody ( p, "dynamic", playerBodyElement )[/code]And suddenly the player just drops down. applyForce seems to have zero effect now. I can't for the life of me figure out why it stopped working. Any ideas would be greatly appreciated. [import]uid: 215620 topic_id: 35547 reply_id: 335547[/import]

hi!

I ran your code. Its weird because the first time the shape just drop down as you mentioned.
But subsequent run is ok and i cannot reproduce the "drop down problem.

As for the applyForce has zero effect, it is probably your line 4 ,addBody, is p instead of player.

burhan [import]uid: 74883 topic_id: 35547 reply_id: 141288[/import]

Looks like you declared the body vertices in counter-clockwise order. This causes all kinds of weird behavior. You need to go clockwise on your polygonal body points, and don’t allow any concave bends (you aren’t here, but just as a future note).

Best regards,
Brent Sorrentino [import]uid: 200026 topic_id: 35547 reply_id: 141294[/import]

The player vs p thing is not a problem, this is because these objects are in different functions and are passed along differently.

Meanwhile i had tried to debug the problem, and noticed that the applyForce still works, only the player had become about 20 times heavier then before, so it had virtually no effect. Increasing the power of the applyForce function brought back the controls, but the collisions were way off.

The problem was indeed the clockwise thing! When i switched around the second and third points, the collisions started working like they should, and the weight had diminished to about half of what it was before shaping was applied. It works perfectly now :slight_smile:

Thank you for solving this mystery!

[import]uid: 215620 topic_id: 35547 reply_id: 141315[/import]

hi!

I ran your code. Its weird because the first time the shape just drop down as you mentioned.
But subsequent run is ok and i cannot reproduce the "drop down problem.

As for the applyForce has zero effect, it is probably your line 4 ,addBody, is p instead of player.

burhan [import]uid: 74883 topic_id: 35547 reply_id: 141288[/import]

Looks like you declared the body vertices in counter-clockwise order. This causes all kinds of weird behavior. You need to go clockwise on your polygonal body points, and don’t allow any concave bends (you aren’t here, but just as a future note).

Best regards,
Brent Sorrentino [import]uid: 200026 topic_id: 35547 reply_id: 141294[/import]

The player vs p thing is not a problem, this is because these objects are in different functions and are passed along differently.

Meanwhile i had tried to debug the problem, and noticed that the applyForce still works, only the player had become about 20 times heavier then before, so it had virtually no effect. Increasing the power of the applyForce function brought back the controls, but the collisions were way off.

The problem was indeed the clockwise thing! When i switched around the second and third points, the collisions started working like they should, and the weight had diminished to about half of what it was before shaping was applied. It works perfectly now :slight_smile:

Thank you for solving this mystery!

[import]uid: 215620 topic_id: 35547 reply_id: 141315[/import]