Howdy, Stranger!

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

I think I have some clipping going on

in Bugs Posts: 23

My code takes a cubemodel, modifies its leftmost upper positions into lower positions, and the resulting model is a ramp that is supposed to be used to define the shape for physical interaction.

You’re supposed to be able to drop a ball atop the ramp and have it react accordingly.

However there seems to be some clipping going on. When you drop your first sphere, the first dropped sphere goes through the ramp and the plane it sits on.

If you were to drop a second sphere the second dropped sphere goes through the ramp but seemingly sits on the plane. If you were to continue dropping spheres they’ll stack atop each other until the fifth or so sphere, at which point they’ll roll their own separate ways either left or right of the ramp.

Here’s the code:

``````displayMode(OVERLAY)
function setup()

parameter.integer("CamHeight",-HEIGHT/2,HEIGHT/2,HEIGHT/2)

-- 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),vec3(0,0,0))

red = "floor.model.positions = {"
for d = 1,#floor.model.positions do
print("floor #",d,"  vec3",floor.model.positions[d])
red = red..",".."vec3("..floor.model.positions[d].x..","..floor.model.positions[d].y..","..floor.model.positions[d].z..")"
end
red = string.gsub(red,"{,","{").."} \n\n floor.model.indices = {"
for r = 1,#floor.model.indices do
print(floor.model.indices[r],",")

red = red..","..floor.model.indices[r]
end
red = string.gsub(red,"{,","{").."}"

--pasteboard.text = red
--  close()

mate = craft.material("Materials:Standard")

mate.diffuse = color(255, 255, 255, 255)
floor.material = mate

floor:get(craft.rigidbody).sleepingAllowed = false

--print("vertexCount ",floor.model.vertexCount," indexCount",floor.model.indexCount)
for i = 1,#floor.model.positions do
h = floor.model:position(i)

-- print("index #",i," = vec3(",h,")")
end
ramp = scene:entity()
ramp.position = vec3(HEIGHT/2,2,HEIGHT/2)

ramp.model = craft.model.cube(vec3(13,130,13),vec3(0,0,0))
print(" theramp indexCount",ramp.model.indexCount,"theramp verts",ramp.model.vertexCount)
for out = 1,#ramp.model.positions do --this loop modifies the cube model into a simple ramp
if ramp.model.positions[out].x < 0 then
sidex = "left"
elseif ramp.model.positions[out].x > 0 then
sidex = "right"

end
if ramp.model.positions[out].y < 0 then
sidey = "down"
elseif ramp.model.positions[out].y > 0 then
sidey = "up"

end

print(sidex..sidey.."#"..out..": vec3("..ramp.model.positions[out].x..","..ramp.model.positions[out].y..","..ramp.model.positions[out].z..")")
if sidey == "up" and sidex == "left" then
sidey = "down"
ramp.model:position(out,ramp.model.positions[out].x,ramp.model.positions[3].y,ramp.model.positions[out].z)
print("now",sidex..sidey.."#"..out..": vec3("..ramp.model.positions[out].x..","..ramp.model.positions[out].y..","..ramp.model.positions[out].z..")")

end
end

ramp:add(craft.shape.model,ramp.model)--since you no longer are using a cube the newly formed model is

surface = craft.material("Materials:Standard")
surface.diffuse = color(0, 27, 255, 255)
ramp.material = surface

verticalx,horizontaly = 0,0

-- Create a new entity

bx = {}

scene.sun.position = vec3(0,0,0)

end

function update(dt)
-- Update the scene (physics, transforms etc)

scene.camera.y = CamHeight
scene.camera.eulerAngles = vec3(verticalx,horizontaly,0)
-- floor.active = true
bx[#bx + 1] = scene:entity()
bx[#bx].position = vec3(scene.camera.x,scene.camera.y,scene.camera.z)
--surface = craft.material("Filters:Edge")

-- surface =
-- surface.diffuse = color(math.random(0,255),math.random(0,255),math.random(0,255),255)

-- surface.normalMap = ""
dimensions = vec3(6,13,6)

bx[#bx].model = craft.model.icosphere(13,3,vec3(0,0,0))
bx[#bx].material = craft.material("Materials:Standard")

bx[#bx].material.diffuse = color(math.random(0,255),math.random(0,255),math.random(0,255),255)

bx[#bx]:get(craft.rigidbody).sleepingAllowed = false

bx[#bx]:get(craft.light).distance = 1024
bx[#bx]:get(craft.light).color = color(0, 0, 0, 122)
bx[#bx]:get(craft.light).angle = 45

print("dropped")

end
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 touch.tapCount == 2 and touch.state == BEGAN then