Simple barebones physics collision not happening - any idea why?

This code creates a ball which falls onto a long rectangle - except it actually falls right through the rectangle. Any clue what’s happening? Thanks.

-- Ball.lua

Ball = class()

function Ball:init(x,y,r)
    self.r = r
    self.body = physics.body(CIRCLE,r)
    self.body.x = x
    self.body.y = y

function Ball:draw()
    fill(255, 15, 0, 255)

-- Main.lua

function setup()
    floor = physics.body(POLYGON, vec2(0,0), vec2(WIDTH,0), vec2(WIDTH,20), vec2(0,20))
    floor.x = 0
    floor.y = 20
    ball = Ball(144,267,10)

function draw()
    background(40, 40, 50)

    -- Draw the rectangle
    stroke(38, 255, 0, 255)
    old = floor.points[4]
    for k,v in pairs(floor.points) do
        line(old.x, old.y, v.x, v.y)
        old = v

function collide(contact)

Please see @Ipda41001 posted

Just add

 Floor.type = STATIC

From the documentation, “Static bodies are unaffected by forces and collisions.” Sounds discouraging.

STATIC just means the body can not move (by force, you can still move it manually). Other bodies can collide with it, but gravity won’t cause it to fall, and other collisions won’t cause it to move. STATIC is best used for things like walls, floors, platforms, and so on.

Ah, thanks. Both STATIC and KINEMATIC make them collide correctly - why doesn’t DYNAMIC, do you know?

I think the floor is probably falling due to gravity when it’s not static. You’d need to hold it in place with a joint or disable gravity.

Ah, of course! Thanks so much!

I realize this is a slightly older thread, but I’m hoping someone might answer a question. I ran this code, but the ball seems to land slightly ABOVE the box. I can’t seem to figure out why this is. Anyone able to help?

It’s the way the floor is drawn

Floor.y = 20

But floor.y isn’t added when the lines of the floor are drawn.

The example

uses translate() to correct for floor.x, floor.y

Thanks to Ipda41001, whoever you are! I wondered if that was the problem but couldn’t quite tell. I’ll give your suggestion a try. I don’t quite understand the translate function (or any of this, really) but learning by doing seems like a good way…!

Ipad41001, codea lua addict and geek of mystery … Spoon! (The Tick cartoon refrenence)

is there any way to code collision with joints? (joint type DISTANCE btw)