# help with physics.body

How do you make it so the ball doesnt gain speed when it hits the wall?

``````displayMode(FULLSCREEN)
supportedOrientations(PORTRAIT)

function setup()

strokeWidth(2)
stroke(255, 255, 255, 255)
noFill()
--ellipseMode(CENTER)

top = physics.body(EDGE, vec2(0, HEIGHT), vec2(WIDTH, HEIGHT))
bottom = physics.body(EDGE, vec2(0, 0), vec2(WIDTH, 0))
left = physics.body(EDGE, vec2(0, 0), vec2(0, HEIGHT))
right = physics.body(EDGE, vec2(WIDTH, 0), vec2(WIDTH, HEIGHT))

ball = physics.body(CIRCLE, 10)
ball.position = vec2(WIDTH/2, HEIGHT/2)
ball.linearVelocity = vec2(200, 200)
ball.restitution = 10
ball.friction = 0

--physics.gravity(0, 0)
ball.gravityScale = 3

ball2 = physics.body(CIRCLE, 40)
ball2.position = vec2(WIDTH/2, HEIGHT/8)
ball2.linearVelocity = vec2(200, 200)
ball2.restitution = 0
ball2.friction = 0
ball2.type=STATIC

--physics.gravity(0, 0)
ball2.gravityScale = 0

end

function draw()

background(45, 45, 45, 255)
-- fill(255, 255, 255, 255)
ellipse(ball.x, ball.y, 20)
ellipse(ball2.x,ball2.y,100,100)
-- line(ball.x, ball.y, ball.x + 38 * math.cos(ball.angle), ball.y + 38 * math.sin(ball.angle))

end

function touched(t)
if math.abs(t.x-ball2.x)<200 and math.abs(t.y-ball2.y)<200 then
ball2.x=t.x
ball2.y=t.y
end
end
``````

Here is the code.

Change the restitution (“bounciness”) to a value less than 1. Set it to 0 for no elasticity, 1 for “perfect” elasticity, and higher than that to make it super elastic. You currently are setting it to 10.

Thanks that worked good. I set it to 1.1 so it slowly gets faster.