Static bodies and new entities in Craft (was: Noob Questions)

Hello,

I am trying to develop a program that accomplishes two tasks.

The first task is to create a static body in craft and a dynamic body which interact such that the first body is much like a floor and upholds the second body which has gravity (a ball falling to the ground).

The second objective is to create a class and use the entity:add() method with that custom class and in a very simple way understand what that does.

As of now I have a dynamic icosphere which falls through a “floor” :frowning: and I don’t know how to setup a custom class for the add method.

Any help appreciated.

@bjhobson12 Here’s something I already had.

displayMode(FULLSCREEN)

function setup()
    assert(OrbitViewer, "Please include Cameras (not Camera) as a dependency")
    fill(255)
    scene = craft.scene()
    skyMaterial=scene.sky.material
    skyMaterial.sky=color(0, 62, 255, 255)
    skyMaterial.horizon=color(99, 255, 0, 255)
    scene.sun.rotation=quat.eulerAngles(20,45,-30)
    v=scene.camera:add(OrbitViewer, vec3(0,0,0), 100, 0, 200)
    v.rx,v.ry=20,20
    createRect()
    createSphere()
end

function draw()
    update(DeltaTime)
    scene:draw()    
    text("Drag your finger on the screen to rotate the cube",WIDTH/2,HEIGHT-100)
end

function update(dt)
    scene:update(dt)
end

function createRect() 
    c1=scene:entity()
    w=c1:add(craft.rigidbody,STATIC)
    w.restitution=1
    c1.position=vec3(0,0,0)
    c1.model = craft.model.cube(vec3(25,1,25))
    c1:add(craft.shape.model,c1.model)
    c1.material = craft.material("Materials:Standard")
    c1.material.map = readImage("Blocks:Trunk White Top")
end

function createSphere()
    sphere1=scene:entity()
    s1=sphere1:add(craft.rigidbody,DYNAMIC)
    s1.linearVelocity=vec3(0,0,0)
    s1.restitution=1
    sphere1.position=vec3(0,30,0)
    sphere1.model = craft.model.icosphere(1,5)
    sphere1:add(craft.shape.sphere,1)
    sphere1.material = craft.material("Materials:Specular")
    sphere1.material.diffuse=color(255,0,0)
end

You are awesome—seriously

Just a side node, you don’t have to add the model (this doesn’t do anything), just assigning it will work.

@John Are you talking about the 2 lines I show below. If I comment them out, everything looks OK but the physics part doesn’t work. The ball passes through the floor. I tried commenting other lines, but then either the object doesn’t show or I get an error.

    c1:add(craft.shape.model,c1.model)

    sphere1:add(craft.shape.sphere,1)

Ah, never mind I missed the craft.shape. part, which makes sense. You were right.