this one works for me,i am posting it in case some new noob wants it.
the only problem with that may be the speed of the asteroids but i like it.
local function createAsteroid()
if (ship.isBodyActive==true)then
local newAsteroid = display.newImageRect( mainGroup, objectSheet, 1, 102, 85 )
table.insert( asteroidsTable, newAsteroid )
physics.addBody( newAsteroid, “dynamic”, { radius=40, bounce=0.8 } )
newAsteroid.myName = “asteroid”
local whereFrom = math.random( 3 )
if ( whereFrom == 1 ) then
– From the left
newAsteroid.x = -60
newAsteroid.y = math.random( 250 )
– newAsteroid:setLinearVelocity( math.random( 40,120 ), math.random( 20,60 ) )
newAsteroid:setLinearVelocity( (ship.x - newAsteroid.x) , ship.y - newAsteroid.y )
elseif ( whereFrom == 2 ) then
– From the top
newAsteroid.x = math.random( display.contentWidth )
newAsteroid.y = -60
– newAsteroid:setLinearVelocity( math.random( -40,40 ), math.random( 40,120 ) )
newAsteroid:setLinearVelocity( (ship.x - newAsteroid.x), ship.y - newAsteroid.y)
elseif ( whereFrom == 3 ) then
– From the right
newAsteroid.x = display.contentWidth + 60
newAsteroid.y = math.random( 250 )
– newAsteroid:setLinearVelocity( math.random( -120,-40 ), math.random( 20,60 ) )
newAsteroid:setLinearVelocity( (ship.x - newAsteroid.x) , ship.y - newAsteroid.y)
end
newAsteroid:applyTorque( math.random( -6,6 ) )
end
end