event.contact

Type PhysicsContact
Event collision
Revision Current Public Release (2018.3326)
Keywords collision, contact

Overview

During a collision, there are multiple contact points that occur. You can manipulate these contact points to create certain effects.

Gotchas

You should not hold onto the contact object. It is only valid in the scope of your collision listener.

Properties

Example

local platform = display.newRect( 0, 0, 280, 30 )
platform.surfaceType = "superbounce"
platform.x, platform.y = display.contentCenterX, display.contentCenterY+80
physics.addBody( platform, "static", { bounce=0.0, friction=0.3 } )
 
local ball = display.newCircle( 0, 0, 15 )
ball.x, ball.y = display.contentCenterX, display.contentCenterY-40
physics.addBody( ball, "dynamic", { bounce=0.0, radius=20 } )
 
local function onCollision( self, event )
 
   local collideObject = event.other
   if ( collideObject.surfaceType == "superbounce" ) then
      event.contact.bounce = 20  -- Magnify bounce for this specific collision
   end
end
 
ball.collision = onCollision
ball:addEventListener( "collision" )