Collison and Vector fun!

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Shanulu
Prole
Posts: 21
Joined: Mon Jun 24, 2013 11:34 pm

Collison and Vector fun!

Post 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)
Attachments
bouncetest.love
(26.66 KiB) Downloaded 141 times
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 7 guests