Howdy, Stranger!

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

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

edited September 30 in Codea Craft Posts: 2

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” :( and I don’t know how to setup a custom class for the add method.

Any help appreciated.

Comments

  • dave1707dave1707 Mod
    Posts: 7,880

    @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

  • JohnJohn Admin Mod
    Posts: 582

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

  • dave1707dave1707 Mod
    Posts: 7,880

    @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)
    
  • JohnJohn Admin Mod
    Posts: 582

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

Sign In or Register to comment.