Rotating

hey guys 

 i want all the enemies present on the screen to rotate after a collision

enemies are inserted into a table…

- code of enemy spawning virus[enemyCounter] = display.newRect(sceneGroup , 0,0, 50,50) virus[enemyCounter].x = math.random(rod1.x + rod1.width, screenRight - rod1.width) virus[enemyCounter].y = screenTop - virus[enemyCounter].height virus[enemyCounter].name = "enemy" physics.addBody(virus[enemyCounter],"dynamic") virus[enemyCounter].isFixedRotation = false transition.to(virus[enemyCounter], {y = screenBottom - virus[enemyCounter].height \* 0.5, time =enemyTravelSpeed, onComplete = function(self) if self ~= nil then display.remove(self); self = nil ; end end }) -- code of rotating after collision for i = 1, #virus do trans\_enemies = transition.to( virus[enemyCounter], { rotation = virus[enemyCounter].rotation+360, time=1500} ) end

but that rotating code didn’t seem to work :frowning: only one or two enemies present on the screen rotates

First let me start off by say transition.to is not recommended on physics body’s. That being said in you for loop
replace this

transition.to( virus[enemyCounter]

With this

transition.to( virus[i]

Just to make sure that the knowledge doesn’t get lost or misinterpreted, transitions are fully legal with physics bodies, however you need to know how to implement them properly (so basically, they shouldn’t just be blindly applied in a physical simulation).

Some specific notes are given here:

https://docs.coronalabs.com/guide/physics/limitations/index.html#transitions

Best regards,

Brent

First let me start off by say transition.to is not recommended on physics body’s. That being said in you for loop
replace this

transition.to( virus[enemyCounter]

With this

transition.to( virus[i]

Just to make sure that the knowledge doesn’t get lost or misinterpreted, transitions are fully legal with physics bodies, however you need to know how to implement them properly (so basically, they shouldn’t just be blindly applied in a physical simulation).

Some specific notes are given here:

https://docs.coronalabs.com/guide/physics/limitations/index.html#transitions

Best regards,

Brent