It allows you to use vectors like so in the code below.
Code: Select all
--I used this within a collision callback for my pong game
local velx, vely = coll:getVelocity()
local IncidentVec = Vector.new( velx, vely )
local speed = IncidentVec:Length()
local colx, coly = coll:getNormal()
local Normal = Vector.new( colx, coly )
Normal:Normalize()
local DotProduct = Normal:Dot( IncidentVec * -1 ) --reflect the bounce
local Dir = ( 2 * Normal * DotProduct ) + IncidentVec
Dir:Normalize()
someBodyObject:setLinearVelocity( Dir.x * speed, Dir.y * speed )
Enjoy!
Demo:
http://www.blackopsservers.com/blackops ... _demo.love
Demo shows a ball continuously bouncing around on your screen.
Press space to reset the ball and randomly punt it again.