I am making a game in which I am spawning obstacles that move at different velocities upon re-spawning. Here is the code:
function badguy.move()
for i = 1, #obstacle, 1 do
aSpeed = math.random(-230, -90)
if obstacle[i].x < 0 then
score = score + 1
scoreText.text = score
obstacle[i].x = 500
else
obstacle[i]:setLinearVelocity( aSpeed, 0 )
end
end
end
As you can see, I am looping through an array of objects to check whether they have passed a certain x value (to re-spawn) and assigning them a random velocity.
So far, all that is happening is that the obstacles are shaking left and right but aren't really changing velocities when they re-spawn. Any help would be appreciated.
Aucun commentaire:
Enregistrer un commentaire