Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Physics polygon type body move

edited November 2012 in Questions Posts: 65

I am having trouble with moving a polygon type physics body.
For example

box = physics.body(POLYGON, vec2(WIDTH/2-100,50), vec2(WIDTH/2+100,50), vec2(WIDTH/2+100,250), vec2(WIDTH/2-100,50))
box.type = STATIC

I was trying to move by changing box.x and box.y value. But the polygon representation on the screen doesn't move.
Any idea??


  • Posts: 666

    Try kinematic instead.

  • edited November 2012 Posts: 437

    Uhm, try something like this:

    -- BoxMove
    -- Use this function to perform your initial setup
    function setup()
        pdb = PhysicsDebugDraw()
        box = createBox(WIDTH/2,HEIGHT/2,20,20)
        box.type = STATIC
    function createBox(x,y,w,h)
        -- polygons are defined by a series of points in counter-clockwise order
        local box = physics.body(POLYGON, vec2(-w/2,h/2), vec2(-w/2,-h/2), vec2(w/2,-h/2), vec2(w/2,h/2))
        box.interpolate = true
        box.x = x
        box.y = y
        box.restitutions = 0.25
        box.sleepingAllowed = false
        return box
    -- This function gets called once every frame
    function draw()
        -- This sets a dark background color 
        background(40, 40, 50)
        -- This sets the line thickness
        -- Do your drawing here
    function touched(touch)
        if touch.tapCount == 1 then
            box.x = touch.x
        elseif touch.tapCount == 2 then
            box.y = touch.y

    Using the PhysicsDebugDraw from Physics Lab example

Sign In or Register to comment.