Page 1 of 1

Collison and Vector fun!

Posted: Wed Aug 07, 2013 3:53 am
by Shanulu
Hello me again! I've started messing around with physics and am having trouble with the call backs associated with it. To be more precise I am having trouble getting my ball to bounce (again!). I am using vector from HUMP(?)... It seems (through a series of Print functions) my ball tries to bounce, mirrors its vector but is still touching the other object, and then just bounces again back into itself thus creating a loop.

My code is as follows which I think is correct, using this site for reference and the vector function mirrorOn():

Code: Select all

function beginContact(a, b, coll)
	local n = vector.new(coll:getNormal()) --our normal vector
	for _, ball in ipairs(balls) do
		if ball.fixture == a or ball.fixture == b then
			v = vector.new(ball.body:getLinearVelocity())
			v_ = v:mirrorOn(n)
			ball.hv, ball.vv = v_:unpack()
		end
	end
end
So my question is two part: Is there something glaringly wrong with my code? and/or How do I prevent this from happening? I've tried using preSolve() but it didn't work (although I'm not entirely sure what it is, I believe it to be the frame of or before the collision, with postSolve being after? So I guess three-part as clarification would be immensely appreciated!)

Here is a .love but beware it's just prototyping right now... Left and Right arrows move the paddle. The sides have physics based walls as well. The ball starts going up and right (for a proper bounce test)