I am making a pong game using the inbuilt physics engine but having trouble with the bats. would I use the KINEMATIC body type and if so how?
@Coder You could always look at the Brickout example. That’s similar to pong. All your answers could be in there.
@Paul123 @dave1707 already mentioned the example.
@Coder Heres a small example:
function setup()
--setup walls
displayMode(FULLSCREEN)
bottom = physics.body(EDGE,vec2(1,1),vec2(WIDTH,1))
bottom.restitution = 1
bottom.friction = 0
right = physics.body(EDGE,vec2(WIDTH,1),vec2(WIDTH,HEIGHT))
right.restitution = 1
right.friction = 0
top = physics.body(EDGE,vec2(1,HEIGHT),vec2(WIDTH,HEIGHT))
top.restitution = 1
top.friction = 0
left = physics.body(EDGE,vec2(1,1),vec2(1,HEIGHT))
left.restitution = 1
left.friction = 0
--setup Paddle
bottomPaddle = physics.body(POLYGON,vec2(0,0),vec2(0,25),vec2(100,25),vec2(100,0))
bottomPaddle.type = KINEMATIC
bottomPaddle.restitution = 1.01
bottomPaddle.x = WIDTH/2
bottomPaddle.y = 100
--setup Ball
ball = physics.body(CIRCLE,25)
ball.restitution = 1
ball.x = WIDTH/2
ball.y = HEIGHT/2
ball.linearVelocity = vec2(200,600)
end
function draw()
background(255, 255, 255, 255)
physics.gravity(vec2(0,0))
--draw ball
pushMatrix()
translate(ball.x,ball.y)
rotate(ball.angle)
fill(0, 81, 255, 255)
sprite("Planet Cute:Character Boy",0,0)
--ellipse(0,0,ball.radius *2)
popMatrix()
--draw paddle
pushMatrix()
translate(bottomPaddle.x,bottomPaddle.y)
fill(0, 0, 0, 255)
rect(0,0,100,25)
popMatrix()
end
function touched(t)
if t.state == MOVING then
bottomPaddle.x = bottomPaddle.x + t.deltaX
end
end
Thanks that is what I meant