Hi all,
I’ve got a question regarding the physics in codea.
I’ve got inspired by the game ‘porTable’, which is developed in such a cool way. Have a look to the custom card deck configuration for the full card deck (you don’t have to buy it to see the configuration). With the ‘extended’ switch you can configure every single card in a full 54 cards deck. This is just an example how beautiful this is designed. The whole ‘game’ is designed in such a beautiful way. Every element can be touched and dragged around the table and it really feels ‘real’.
This realistic handling of objects is what I would like to do on my own.
I found an example in the forums (or it was one of the built-ins) which I tried to modify. I tweaked some parameters but it always feels far from being objects like domino bricks or something that are dragged around a table.
Did anybody try something similar or just have an idea how the physics parameters should be?
This is what my sample project looks like:
Thank you very much for your help in advance!
Regards,
Jan
supportedOrientations(LANDSCAPE_ANY)
function setup()
watch("CurrentTouch.deltaX")
inTouch = false
ball = physics.body(CIRCLE, 50)
ball.x = WIDTH / 2
ball.y = HEIGHT / 2
physics.gravity(0,0)
walls = {
physics.body(EDGE, vec2(0, 0), vec2(WIDTH, 0)),
physics.body(EDGE, vec2(0, 0), vec2(0, HEIGHT)),
physics.body(EDGE, vec2(WIDTH, HEIGHT), vec2(WIDTH, 0)),
physics.body(EDGE, vec2(WIDTH, HEIGHT), vec2(0, HEIGHT)),
}
for k, v in ipairs(walls) do
v.restitution = 1
end
bodies = {}
for i = 1, 5 do
bodies[i] = physics.body(CIRCLE, 50)
bodies[i].position = vec2(math.random(WIDTH), math.random(HEIGHT))
-- bodies[i].mass = 100
-- bodies[i].friction = 1000000
end
end
function draw()
background(0, 0, 0, 255)
fill(255, 255, 0, 255)
ellipse(ball.x, ball.y, 100)
ball.linearVelocity = vec2(0,0)
fill(255, 0, 0, 255)
for k, v in ipairs(bodies) do
ellipse(v.x, v.y, 100)
end
end
function touched(touch)
touchPoint = vec2(touch.x, touch.y)
if touch.state == BEGAN and ball:testPoint(touchPoint) then
inTouch = true
end
if touch.state == ENDED then
inTouch = false
end
if touch.state == MOVING and inTouch then
ball.linearVelocity = vec2(touch.deltaX, touch.deltaY) / DeltaTime
end
end