change angle during runtime

Hi,

How can i change the angle of the vent during runtime

i can access the vent.angles table, but changing the values in here has no effect.

What i really need is to have the vent to follow a rotating object, think the thrust from a rocket how should i do that?

Cheers,

Tommy

Most of the time, CBEffects pre-calculates angles so that relatively expensive math operations aren’t done each frame. That boosts performance, but makes the angles unchangeable on the fly.

You can set the “preCalculateAngles” parameter in the physics table:

[lua]

– In vent parameters

physics = {

    preCalculateAngles = false

}

[/lua]

When it’s off, velocity vectors are calculated when needed (at runtime) instead of being stored.

  • C

Hi Caleb,

I tried that to no luck, my construct is as follows

 v1 = CBE.newVent { title = "angles", preset = "fountain", positionType = "atPoint", perEmit = 1, x = display.contentCenterX, y = display.contentCenterY, physics = { gravityY = 0, preCalculateAngles = false, angles = { {10,20} } } }

During runtime i do this:

v1.angles = {{245,255}} v1:emit()

the value does change, but particles are still launched in original direction.

Cheers,

Tommy

ahh it seems that during runtime it selects from vent.calculatedAngels i guess it should not or do i need to invoke something to recalculate those ?

Cheers,

Tommy

preCalculateAngles doesn’t work perfectly (litotes alert) when angle ranges are provided.

You can manually recalculate angle ranges with vent.resetAngles(). It’s a rather expensive operation, based on the range of your angles (200-300 is more expensive than 200-220), so do be careful :). If your rocket isn’t rotating too quickly, you can do it in a delay, and with some “has changed” checks, and you shouldn’t be able to notice any problems.

  • C

Thanks for all your help, i ended up writing my own function to set vent.calculatedAngels directly  :) 

Cheers,

Tommy

Ok :slight_smile:

I’ll see if I can implement this feature in a future release. I’ve also thought of completely eliminating the need for manual updating by calculating normals and extruding for the velocity… Wouldn’t take too long, just don’t have much time at the present (deadlines, yay!).

  • C

Most of the time, CBEffects pre-calculates angles so that relatively expensive math operations aren’t done each frame. That boosts performance, but makes the angles unchangeable on the fly.

You can set the “preCalculateAngles” parameter in the physics table:

[lua]

– In vent parameters

physics = {

    preCalculateAngles = false

}

[/lua]

When it’s off, velocity vectors are calculated when needed (at runtime) instead of being stored.

  • C

Hi Caleb,

I tried that to no luck, my construct is as follows

 v1 = CBE.newVent { title = "angles", preset = "fountain", positionType = "atPoint", perEmit = 1, x = display.contentCenterX, y = display.contentCenterY, physics = { gravityY = 0, preCalculateAngles = false, angles = { {10,20} } } }

During runtime i do this:

v1.angles = {{245,255}} v1:emit()

the value does change, but particles are still launched in original direction.

Cheers,

Tommy

ahh it seems that during runtime it selects from vent.calculatedAngels i guess it should not or do i need to invoke something to recalculate those ?

Cheers,

Tommy

preCalculateAngles doesn’t work perfectly (litotes alert) when angle ranges are provided.

You can manually recalculate angle ranges with vent.resetAngles(). It’s a rather expensive operation, based on the range of your angles (200-300 is more expensive than 200-220), so do be careful :). If your rocket isn’t rotating too quickly, you can do it in a delay, and with some “has changed” checks, and you shouldn’t be able to notice any problems.

  • C

Thanks for all your help, i ended up writing my own function to set vent.calculatedAngels directly  :) 

Cheers,

Tommy

Ok :slight_smile:

I’ll see if I can implement this feature in a future release. I’ve also thought of completely eliminating the need for manual updating by calculating normals and extruding for the velocity… Wouldn’t take too long, just don’t have much time at the present (deadlines, yay!).

  • C

Okay was asked in a private message how i updated the vent angle at runtime.

Thought i would answer here, so everyone can benefit.

I have the code below execute every tick

Cheers,

Tommy

[lua]

–v1 is my vent

–self is my img object

local angle = mrad(self.rotation+270)   – we need angle in radians

local xComp = mcos(angle) – the x component

local yComp = msin(angle)   – the y component

v1.x = self.x-xComp*35 --multiply by 35 to have vent off center 

v1.y = self.y-yComp*35

           

local r = (self.rotation+90)*-1

v1.calculatedAngles = {r-1,r,r+1}

v1:emit()

[/lua]

Thanks a lot, Tommy!

-jospic

Okay was asked in a private message how i updated the vent angle at runtime.

Thought i would answer here, so everyone can benefit.

I have the code below execute every tick

Cheers,

Tommy

[lua]

–v1 is my vent

–self is my img object

local angle = mrad(self.rotation+270)   – we need angle in radians

local xComp = mcos(angle) – the x component

local yComp = msin(angle)   – the y component

v1.x = self.x-xComp*35 --multiply by 35 to have vent off center 

v1.y = self.y-yComp*35

           

local r = (self.rotation+90)*-1

v1.calculatedAngles = {r-1,r,r+1}

v1:emit()

[/lua]

Thanks a lot, Tommy!

-jospic