I am hoping someone with a better understanding of the physics engin can give me a suggestion on my code. I have a game in Flash that I am porting to Corona. Basically an Astroids clone. I can’t seem to get the random math correct to apply the correct force and torque to the astroids.
All the astroids seem to only move from left to right on the screen. The speed does very. It’s more about the direction that I am trying to randomize.
Here is the code.
[lua]local function createAstroids( )
for i=1, numberOfAstroidsForThisLevel() do
astroid = display.newImage(“rock_large.png”)
astroid.x = (math.random() * ( 0- display.contentWidth)) + display.contentWidth
astroid.y = 0 - (astroid.height - 2)
astroid_group:insert(astroid)
physics.addBody(astroid, {density=3})
xforce = (math.random() * (0 - display.contentWidth)) + (display.contentWidth * 2)
yforce = ( math.random() * (0 - display.contentHeight)) + (display.contentHeight * 2)
atorque = (math.random() * -1000) + 1000
xposition = (math.random() * (0 - astroid.x)) + (astroid.x * 2)
yposition = (math.random() * (0 - astroid.y)) + (astroid.y * 2)
astroid:applyForce(xforce,yforce, xposition, yposition)
astroid:applyTorque(atorque)
end
end[/lua]
Here is the Flash version so that you get a sense of what I am going for. http://matthewsloanwallace.com/flixel-progress-flying-space-rocks-part-6
[import]uid: 6636 topic_id: 3280 reply_id: 303280[/import]