@Jarc The collision still happens, but since you’re controlling the person, you’ll have to code for the collision. If a collision is detected, then don’t allow any motion in the current direction.
Collisions don’t work right if you try to override it. If the objects aren’t free to move on their own, you’ll get a collision detected but it won’t stop a manually moving object.
@dave1707 Sorry to bring this up again but I’m having a hard time understanding what you’re saying. I think the physics engine in Codea needs tweaking. The collision isn’t happening because my collision detector function would tell me. Here is a more simple example(project below). The sprite I don’t have the Dpad linked to collision works on everything but as soon as I link the Joystick to a sprite or collision body the collision only works on falling objects. I got this method from box2D physics simulator engine so not sure why it isn’t working here when physics principles are the same. The sprite I’m controlling shouldn’t be able to walk through the edge line.
displayMode(FULLSCREEN)
function setup()
pic=readImage("Planet Cute:Character Boy")
cx,cy=0,0
sx,sy=WIDTH/2,HEIGHT/2
dx,dy=0,0
--Collider
c1 = physics.body(CIRCLE,100,50) -- sprite collision circle
c1.type=KINEMATIC
c1.x=dx
c1.y=dy
c2 = physics.body(CIRCLE,50) -- falling circle
c2.type=DYNAMIC
c2.x=WIDTH/2
c2.y=600
c2.restitution=1
c3 = physics.body (EDGE, vec2(200,200),vec2(400,400))
c3.x1=200
c3.y1=200
c3.x2=400
c3.y2=400
end
function draw()
background(40, 40, 50)
sprite(asset.builtin.Tyrian_Remastered.Boss_D,c2.x,c2.y)
--collider
popStyle()
stroke(255)
strokeWidth(1)
noFill()
ellipse(c2.x,c2.y,100,100)
line(c3.x1,c3.y1,c3.x2,c3.y2)
pushStyle()
if cx>0 and cy>0 then
drawCirc()
end
sx=sx+dx
sy=sy+dy
c1.x=sx
c1.y=sy
sprite(pic,sx,sy)
sprite(pic,c1.x,c1.y)
end
function touched(t)
if t.state==BEGAN then
cx,cy=t.x,t.y
end
if t.state==MOVING then
if insideCircle(t.x,t.y) then
dx=(t.x-cx)/10
dy=(t.y-cy)/10
else
cx,cy=0,0
dx,dy=0,0
end
end
if t.state==ENDED then
cc,cy=0,0
dx,dy=0,0
end
end
function insideCircle(x,y)
-- check if touch is inside of circle or ellipse
a,b=100,100 -- radius of circle or a,b of ellipse
if (x-cx)^2/a^2+(y-cy)^2/b^2 <= 1 then
return true
end
return false
end
function drawCirc()
fill(255, 255, 255, 50)
ellipse(cx,cy,50) -- draw circle center
fontSize(15)
fill(233, 80, 133)
text("Up",cx,cy+80)
text("Down",cx,cy-80)
text("Right",cx+80,cy)
text("Left",cx-80,cy)
fontSize(10)
text("DTL",cx-60,cy+60)
text("DTR",cx+60,cy+60)
text("DBL",cx-60,cy-60)
text("DBR",cx+60,cy-60)
noFill()
stroke(255,255,255,50)
strokeWidth(4)
ellipse(cx,cy,200) -- draw outer circle
end
function collide(c) -- this gets called when a collision occurs
if c.state==BEGAN then
print("\
collision")
print("radius of body A ",c.bodyA.radius)
print("radius of body B ",c.bodyB.radius)
end
end