简体   繁体   中英

Corona Physics not pushing bodies

I am build a top down view game. I have two physics bodies. The player and a house. I don't want the player to be able to walk where the house is. I have added the two bodies.

physics.addBody(part.house, "static", {shape=bodies.houses[1]})

physics.addBody(Player, {density=200,radius=30})

The shape of the house body is done in an array.

bodies.houses = {
                    {-120, 90, -60, 90, -60, 15, 30, 15, 110, -60, 110, -170, 30, -245, -120, -245},
                    {10, 10, 10, 0, 0, 0, 0, 10},
                    {10, 10, 10, 0, 0, 0, 0, 10}
                }

The body shape itself sits on the image perfectly. But the player can still run over the house. Please help.

--EDIT 1 The player is moved using this library

local StickLib   = require("lib_analog_stick")

The shape of your building is not convex as required by the corona docs :

corona docs : Polygonal shapes must be entirely convex. You cannot create shapes with concave bends, for example a bowl or cup. To accomplish such a task, you must assemble the body from multiple polygons, as explained in Multi-Element Bodies below.

convex : In a convex polygon, a line segment between two points on the boundary never goes outside the polygon.

You can see it's not convex because the black line segment leaves the shape but both ends are on the boundaries. You can break off the bottom rectangle bit (under green line) into another body to fix this.

physics.addBody(part.house, "static",
   {shape={-120, 15, -60, 15, 30, 15, 110, -60, 110, -170, 30, -245, -120, -245}},
   {shape={-120, 90, -60, 90, -60, 15, -120, 15}}
)

非凸形

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM