Collision

Hello,

I want to make a ball touch a power up and go faster. Can you give me the code to do that? [import]uid: 23689 topic_id: 10319 reply_id: 310319[/import]

Hi Michael,

Typically people wont write code for you for free; the community is more for asking how to do something you’re having trouble with, getting some pointers, then doing it yourself.

To make a ball touch a power up you want them to collide, I assume - so check out the Collision Detection API here; http://developer.anscamobile.com/content/game-edition-collision-detection

Then to make it go faster, you would edit the ball’s properties - I’m not sure how you are moving it, so I can’t say what you’d edit specifically, but whatever controls its speed to begin with.

Peach :slight_smile: [import]uid: 52491 topic_id: 10319 reply_id: 37761[/import]

HI,
for me the colision is unclear do you need it to be a physic body, or do you want it to bee a graphic? I thing to make the ball go faster I need to apply a linear impulse. Is that true ? [import]uid: 23689 topic_id: 10319 reply_id: 39397[/import]

thank you
now I tried to do a simple app that makes the ball change colors every time it hits the line. there is a problem I looked all over and did not find the sulution can you help me?
here is the code:

local physics = require “physics”
physics.start(true)
–physics.setDrawMode (“hybrid”)

local ball = display.newCircle( 0, 0, 25)
ball.x = 100
ball.y = 20
physics.addBody( ball, {bounce = 0, radius = 27.5, friction = 5})

local line = display.newLine( 0,-200, 0,-5 )
line:setColor( 255, 200, 100 )
line.width = 8
line.x = 100
line.y = 140
physics.addBody( line,“static”, {bounce = 1, radius = 27.5, friction = 5})

function ball:collision(e)
if(e.phase == “began”) then
if(e.other.type == “line”) then
local r = math.random( 0, 255 )
local g = math.random( 0, 255 )
local b = math.random( 0, 255 )

ball:setCircleColor( r, g, b )

end
end
end

ball:addEventListener(“colision”, ball)
[import]uid: 23689 topic_id: 10319 reply_id: 39425[/import]

You say there is a problem but not what the problem is.

Please be more specific. [import]uid: 52491 topic_id: 10319 reply_id: 39447[/import]

Well the ball is suppose to collide with the line and change colors, but when it colides it doesn’t change colors. I tried the debugger and read over the forums and the tutorial of the colision detection and I can’t find out whats wrong [import]uid: 23689 topic_id: 10319 reply_id: 39461[/import]