Collision Detection

Hello,

I am making a collision ball and ball1, when they hit a linear impulse is added. But the code that i have been using does not have been successfully working. What is wrong?
function ball:collision( event )
if event.phase == “began” then
ball:applyLinearImpulse(0, -0.2, ball.x, ball.y)
end

return true
end

I have also tried doing some things like this :
But have failed.

function ball:collision(e)
if(e.phase == “began”) then
if(e.other.type == “ball”) then
ball1:applyLinearImpulse(0, -0.2, ball.x, ball.y)
end

ball:addEventListener(“collision”, ball)

Thank you. [import]uid: 23689 topic_id: 10836 reply_id: 310836[/import]

The syntax you are using for your function calls is incorrect. You need to remove the semicolon. So in other words change this line:

function ball:collision( event )

to this:

function ballCollision( event )

and make sure you have an event listener for physics object(s) you want to call this event. [import]uid: 27965 topic_id: 10836 reply_id: 39474[/import]

I have used this new code, but it still has failed.
function ballCollision(e)
if(e.phase == “began”) then
if(e.other.type == “ball”) then
ball1:applyLinearImpulse(0, -0.2, ball1.x, ball1.y)
end

ball:addEventListener(“collision”, ball)
[import]uid: 23689 topic_id: 10836 reply_id: 39492[/import]

Your “eventListener” is not calling a function. Try adding this line before it:

ball.collision = ballCollision Take a look at the collision detection documentation for in depth details.
http://developer.anscamobile.com/content/game-edition-collision-detection#Local_collision_listeners
[import]uid: 27965 topic_id: 10836 reply_id: 39515[/import]

Okay thankyou now its working. If I want to get more complex and add more bodies and say if this ball hits the line it does so
and if this ball hits the image it does so and so.
tahnkyou [import]uid: 23689 topic_id: 10836 reply_id: 39523[/import]