push an object after hitting Sensor

I have a ball I want to shoot in the y direction after it rolls over a sensor. I can’t get what I’m doing wrong.
Thanks,
Dan

[code]
local function onVelocity( self, event )
orb:applyLinearImpulse( 0, -200, orb.x, orb.y )
end

– velocity Sensor
local pipeSensor = {}
local sensorRadius = 20
pipeSensor = display.newCircle( 30,30, sensorRadius )
game:insert( pipeSensor )
pipeSensor.isVisible = true
pipeSensor.x = 455 + xmoveplacement
pipeSensor.y = 165 + ymoveplacement
pipeSensor.radius=sensorRadius
pipeSensor.isSensor = true

pipeSensor:addEventListener( “collision”, onVelocity ) [/code] [import]uid: 78446 topic_id: 13820 reply_id: 313820[/import]

you haven’t added pipeSensor as a physics body. otherwise the code looks fine.
see the code below
[lua]local physics =require(“physics”)
physics.start()
physics.setGravity(0, 9.8)

local orb = display.newCircle(100,100,15)
physics.addBody(orb , {density=.4, friction=.4, bounce=.4 })

local function onVelocity( self, event )
print(“collided”)
orb:applyLinearImpulse( 0, -200, orb.x, orb.y )
end

– velocity Sensor
local sensorRadius = 20
local pipeSensor = display.newCircle( 100,200, sensorRadius )
physics.addBody(pipeSensor ,“static”)
pipeSensor.radius=sensorRadius
pipeSensor.isSensor = true

pipeSensor:addEventListener( “collision”, onVelocity ) [/lua] [import]uid: 71210 topic_id: 13820 reply_id: 50817[/import]

Thanks,
What happens now is the orb hits the sensor and bounces off. Is there a way to have it roll over the sensor and increase speed in y direction.

What I have is an L shaped pipe, as the orb rolls down the pipe and hits the elbow, I have the sensor just above the elbow, I then want to shoot the orb on it’s way up and out.

Thanks

Dan [import]uid: 78446 topic_id: 13820 reply_id: 51008[/import]

if the sensor is inside the pipe then this code should work fine right ?
it will look something like this
[lua]local physics =require(“physics”)
physics.start()
physics.setGravity(0, 9.8)

local pipe = display.newRect(100,140,50,200)

local orb = display.newCircle(125,100,15)
orb:setFillColor(0,255,0)
physics.addBody(orb , {density=.4, friction=.4, bounce=.4 })

local function onVelocity( self, event )
print(“collided”)
orb:applyLinearImpulse( 0, -200, orb.x, orb.y )
end

– velocity Sensor
local sensorRadius = 20
local pipeSensor = display.newCircle( 125,290, sensorRadius )
pipeSensor:setFillColor(255,0,0)
physics.addBody(pipeSensor ,“static”)
pipeSensor.radius=sensorRadius
pipeSensor.isSensor = true

pipeSensor:addEventListener( “collision”, onVelocity ) [/lua] [import]uid: 71210 topic_id: 13820 reply_id: 51054[/import]

if you want to apply the velocity only after moving over the sensor you should try something like this
[lua]local physics =require(“physics”)
physics.start()
physics.setGravity(0, 9.8)

local pipe = display.newRect(100,140,50,200)

local orb = display.newCircle(125,100,15)
orb:setFillColor(0,255,0)
physics.addBody(orb , {density=.4, friction=.4, bounce=.4 })

local a = 0
local function onVelocity( self, event )
a = a + 1
if a > 1 then
orb:applyLinearImpulse( 0, -200, orb.x, orb.y )
end
end

– velocity Sensor
local sensorRadius = 20
local pipeSensor = display.newCircle( 125,290, sensorRadius )
pipeSensor:setFillColor(255,0,0)
physics.addBody(pipeSensor ,“static”)
pipeSensor.radius=sensorRadius
pipeSensor.isSensor = true

pipeSensor:addEventListener( “collision”, onVelocity ) [/lua] [import]uid: 71210 topic_id: 13820 reply_id: 51055[/import]