Hello, I’m creating a game and I’ve been having some problems with making the objects move the way I want. So basically I have this group of objects that move randomly within the screen borders (I created some walls to avoid them going off screen). I also have another object that moves randomly within the screen but it is not part of the group in fact, it is the “enemy”. I applied linear velocity to all my objects. I’ll paste the code.
–creation of 10 cells
math.randomseed( os.time() )
for i = 1, 10, 1 do
--cell
cell = display.newImageRect( "cell.png", 70, 100 )
cell.x=math.random(display.contentWidth)
cell.y=math.random(display.contentHeight)
--cell physics
physics.addBody(cell, "dynamic", {density=1, friction=0.0, bounce=0.9, radius=30});
cell:setLinearVelocity ( 5000, 5000 )
end
--virus
local virus = display.newImageRect("virus.png", 90,90)
virus.x=display.contentCenterX
virus.y=display.contentCenterY
physics.addBody(virus, "dynamic", {density=1, friction=0.0, bounce=0, radius=15});
virus:setLinearVelocity ( 500, 500 )
Everything seems to function properly but… in the long run each objects lose its velocity until it only “floats” on the screen. I set the velocity to higher numbers but it doesn’t work as their behaviors doesn’t change. They only move faster in the beginning (which I don’t like by the way).
i Just want my objects to keep having the same velocity throughout the game even when they hit each other or the walls… what should i do?
thanks in advance.