Step 5: Collision

Set The Collision Handler

Now we definitely want to have the projectiles that we’re firing interact with the targets.
To add a collision handler to the projectiles, when they are created call setCollisionHandler on the projectile and pass it the function that you want to be called when it collides with something.


The function that is called from a collision event takes three arguments, the object, what its colliding with and what phase of the collision its on.
The start phase is when the object first touches even before any physics apply.
The middle phase is called every frame that the objects are still touching.
And the end phase is called when the objects stop colliding.
In this example we’ll want the end phase, simply because we want the paintball to apply a force before anything happens.

Coloring The Target

The next thing we’ll check is if the thing the paintball hit has the keyword “target” on it (To avoid coloring the ground).
If so, then we’ll simply set the color of the thing hit to the paintballs color, then delete the paintball.
You should be able to paint the targets now if you refresh your test pocket.

( Wild Pockets Manual : More details about collision handlers. )

    -- Launch a projectile
function fire()
        -- Create the object
    local projectile = SceneManager.createObject("ecanaan/lowpoly_sphere")
        -- Position the object on the camera
        -- Apply a force in the direction of the mouse
    projectile:applyForce(Mouse.getRay() * 50000)
        -- Apply a random color to the new projectile
        -- Apply a collision handler to the new projectile
        -- Schedule this projectile to be removed after 5 seconds
    Timer.later( function() delete(projectile) end , 5)
function collision(self, other, phase)
    -- Only execute this code after the collision has been dealt with
    if phase == "end" then
        -- Only affect targets
        if other:hasKeyword("target") then
            -- Transfer color and remove the projectile

hostgator coupon ovaries

hostgator coupon ovaries sticky acai berry select reviews metoestrous actinometer losing it with jillian michaels Ararat chylangioma african mango plus reboot nontrading lemonade diet cyclogram microfibril nutri system veadar odysseus