Below is my code for testing the craft physics
-- Craft Template
displayMode(OVERLAY)
function setup()
-- Create a new craft scene
scene = craft.scene()
scene.camera.position = vec3(HEIGHT/2,HEIGHT/2,HEIGHT/2)
floor = scene:entity()
floor.position = vec3(HEIGHT/2,-1,HEIGHT/2)
floor.model = craft.model.plane(vec2(1024,1024))
mate = craft.material("Materials:Basic")
mate.diffuse = color(255, 255, 255, 255)
floor.material = mate
hardfloor = floor:add(craft.rigidbody,STATIC)
hardfloor.sleepingAllowed = false
hardfloor.awake = true
hardfloor.group = 0
hardfloor.mask = 1
verticalx,horizontaly = 0,0
-- Create a new entity
bx = {}
pog = {}
end
function update(dt)
-- Update the scene (physics, transforms etc)
scene.camera.eulerAngles = vec3(verticalx,horizontaly,0)
scene:update(dt)
end
-- Called automatically by codea
function draw()
update(DeltaTime)
-- Draw the scene
scene:draw()
end
function touched(touch)
if CurrentTouch.state == MOVING then
verticalx,horizontaly = verticalx + CurrentTouch.deltaY,horizontaly + CurrentTouch.deltaX
end
if CurrentTouch.tapCount == 2 then
bx[#bx + 1] = scene:entity()
bx[#bx].position = vec3(CurrentTouch.prevX,HEIGHT/2,CurrentTouch.prevY)
surface = craft.material("Materials:Basic")
surface.diffuse = color(math.random(0,255),math.random(0,255),math.random(0,255))
bx[#bx].model = craft.model.cube(vec3(13,13,13))
bx[#bx].material = surface
bx[#bx]:add(craft.rigidbody,DYNAMIC,13)
bx[#bx]:add(craft.shape.box,vec3(13,13,13))--,vec3(6.5,6.5,6.5))
pog[#pog + 1] = bx[#bx]:get(craft.rigidbody)
pog[#pog].group = 1
pog[#pog].mask = 0
pog[#pog].sleepingAllowed = false
pog[#pog].awake = true
end
end
I called the project Drop the block.
So in the code I repositioned the scene camera, created a floor, tried to attach a STATIC rigidbody. Discovered they dont use tables for filtering like categories/mask would in a default template project. They expect numbers.
So I used numbers, and coded it so that a box is created when you double tap(and of course applied a Dynamic rigidbody to the box and the box shape so that it can be moved by physics), and the camera pivots based on your swipe movement(from a completely independant fixed location).
The box you drop is dropped from thhe same height as the scene camera. Your x,y touch vectors are used for its x,z placement in space.
I’ve skimmed the craft demo code. I don’t see any examples of group/mask being used in code. So thought maybe its in the documentation. The closest I see is in the craft physics raycast, but its not a returned key-value.
The long and short of it is this. When I drop a box? It goes through the plane but it doesn’t land on it.