Query: I have a physics ball to be hit by two paddles (comprised of other physics balls) (think air hockey), however, when the ball is hit, it moves, but does not slide like a normal ball. Thought so is probably because I am not very experienced in the field of physics coding, and am missing some necessary code. Would it be possible to add code to the ball to make it slide while having no additional code applied to the paddles? If not, what would be the best alternative way to make the ball slide?
-- variables for various functions and positions
-- ballpos = vector 2 starting position of the ball
-- pos1 = vector 2 constant position of Player 1's paddle
-- pos2 = vector 2 constant position of Player 2's paddle
function setup()
-- Ball
ball = physics.body(CIRCLE,25)
ball.type = DYNAMIC
ball.position = ballpos
ball.gravityScale = 0
ball.sleepingAllowed = false
-- Player 1's Paddle
Player1 = physics.body(CIRCLE,50)
Player1.type = KINEMATIC
Player1.position = pos1
Player1.gravityScale = 0
Player1.sleepingAllowed = false
-- Player 2's Paddle
Player2 = physics.body(CIRCLE,50)
Player2.type = KINEMATIC
Player2.position = pos2
Player2.gravityScale = 0
Player2.sleepingAllowed = false
end
function draw()
-- Ball
ballpos = ball.position
strokeWidth(0)
fill(255, 255, 255, 255)
ellipse(ball.position.x,ball.position.y,25)
-- Player 1
pos1.x = math.max(70,pos1.x)
pos1.x = math.min(WIDTH-70,pos1.x)
pos1.y = math.max(70,pos1.y)
pos1.y = math.min(HEIGHT/2-50,pos1.y)
Player1.position = pos1
strokeWidth(30)
stroke(255,0,0,255)
fill(0, 0, 0, 255)
ellipse(Player1.position.x, Player1.position.y, 50)
-- Player 2
pos2.x = math.max(70,pos2.x)
pos2.x = math.min(WIDTH-70,pos2.x)
pos2.y = math.max(HEIGHT/2+50,pos2.y)
pos2.y = math.min(HEIGHT-70,pos2.y)
Player2.position = pos2
strokeWidth(30)
stroke(0,255,255,255)
fill(0, 0, 0, 255)
ellipse(Player2.position.x, Player2.position.y, 50)
end