wind effect forces - use physics particles or hidden single object re performance???

Any advice here - I’m about to try to get directional wind to apply forces on floating objects. What approach would you recommend? for example:

a) create wind using lots of small physics particles, then each of these can collide - not sure of performance impacts here however…

b) create an invisible circle that gets fired out with the physics effects and use this to collide - then only one collision/physics particle is required

c) other…

[import]uid: 140210 topic_id: 30066 reply_id: 330066[/import]

Can you specify better how you would like the leafs to behave, so they just move around from a global wind force or do you want the wind to be emitted from a source?? do you want to move the source? so on …

d) Here is one more idea
make a small circle or something, you can make it invisible.
This will be your “wind generator” when objects gets close to this, they will be repelled by a force from this wind object, which will be depend on the distance to the floating objects to be affected.

do something like this

local floatingobjects = {}  
  
local function windforce()  
  
 for j=1,#floatingobjects do  
  
 -- get the distance to objects from the windgenerator  
 dx = windgenerator.x - floatingobjects[j].x  
 dy ......  
 dist = sqrt(dx^2+dy^2)  
  
-- calculate the force which the floats will be affected by  
 force = factor/dist^2  
  
 get the directional force components  
 forceX = cos( atan2(dy,dx))\*force  
 forceY = sin( atain2(du,dx))\*force  
  
 -- apply the force/impulse to the objects   
 floatingobjects[j]:applyForce( forceX,ForceY)  
 end  
end  
  
Runtime:addEventListener( "enterFrame", windforce )  

You can manipulate this as you wish, e.g make the force*math.ran(1,10) to make some wind blast or something…

[import]uid: 162464 topic_id: 30066 reply_id: 120391[/import]

I more had in mind:
a) a fan blowing wind & visually showing the wind with particles.
b) but then in terms of the effect on floating objects the objects would be impacted by the wind both:
c) based on distance from fan and
d) how on-axis the object is to the fan, but also
e) the fan could move direction

So based on the last (e) this is where the forces on the object (when they hit etc) is pretty much based on when & how many wind effect particles that hit them. The concern I had was whether that would make sense or not to have lots of small physics enabled particles from a performance point of view. Hope this makes sense.

[import]uid: 140210 topic_id: 30066 reply_id: 120394[/import]

Im a bit tired, be ye it makes sense :wink:

Hmm, if you want visual showing the wind, then you might as well also use them as “push” objects - so they transfer their energy on collision. I really don’t have any idea of how many wind objects you can have in this case :confused: But i cant think of any other ways to do it, particularly when you need to show the wind…

[import]uid: 162464 topic_id: 30066 reply_id: 120398[/import]

I agree with Zwonkie, if you need to show the wind using some kind of particle effect, then you might as well use them as physical colliders that push the objects they hit with a very slight force (use applyForce, not impulse).

Your wind particles could also be sensors, not “solid” objects. When they hit something like a leaf, your collision function compares the X and Y differences (I wrote a post about this just a few days ago) and you apply the proper fractional, directional force.

If performance is bogging down, you could use 2 emitters that behave similarly in direction, speed, etc. but one emits fewer particles than the other… and those are the physical ones. The other emitter emits those for the visual look of the wind, and more of them.

Brent [import]uid: 9747 topic_id: 30066 reply_id: 120447[/import]

thanks guys

@Brent - re “Your wind particles could also be sensors, not “solid” objects” - this is mainly to minimize performance impacts is it Brent? i.e. I’m guessing sensors “cost less” than physical bodies colliding?

Like the idea too about 2 emitters. Actually the 2nd one could even be invisible and it’s limited particles it sends out invisible too… [import]uid: 140210 topic_id: 30066 reply_id: 120525[/import]

Hi Greg,

I actually didn’t clarify that very well. When I was saying that the “physical” wind particles could be sensors, I was thinking that their collision would be handled with a custom function that applied force to the “leaf” in question, instead of just relying on solid Box2D collision forces to push the leaf. It actually makes the whole scenario a bit more complex, but it might also yield a far more realistic-looking simulation. The wind particles, upon collision, would be compared in X/Y differences compared to the leaf, then you’d apply a very slight force based on this calculation, to push the leaf slightly away.

I discussed this method in my posting here, scroll down just a bit on the page:
http://developer.coronalabs.com/forum/2012/08/14/actions-collisions

Hope this makes sense, it’s combining two separate forum posts but the end purpose is fairly similar.

If this seems overly complicated, you could try just making the particles “solid” (not sensors) and turning the density on them way down, so they would only have a subtle effect on the leaf. The snag there is that the particles would then bounce off the leaves, potentially hitting other leaves if you had many in the path of the wind.

Brent
[import]uid: 9747 topic_id: 30066 reply_id: 120528[/import]

thanks Brent - I’m starting to play with these ideas now - outcomes can be kind of funny at times :slight_smile: I can see now (with the options up my sleeve) it’s a matter of trial and error with the options… [import]uid: 140210 topic_id: 30066 reply_id: 120529[/import]

Can you specify better how you would like the leafs to behave, so they just move around from a global wind force or do you want the wind to be emitted from a source?? do you want to move the source? so on …

d) Here is one more idea
make a small circle or something, you can make it invisible.
This will be your “wind generator” when objects gets close to this, they will be repelled by a force from this wind object, which will be depend on the distance to the floating objects to be affected.

do something like this

local floatingobjects = {}  
  
local function windforce()  
  
 for j=1,#floatingobjects do  
  
 -- get the distance to objects from the windgenerator  
 dx = windgenerator.x - floatingobjects[j].x  
 dy ......  
 dist = sqrt(dx^2+dy^2)  
  
-- calculate the force which the floats will be affected by  
 force = factor/dist^2  
  
 get the directional force components  
 forceX = cos( atan2(dy,dx))\*force  
 forceY = sin( atain2(du,dx))\*force  
  
 -- apply the force/impulse to the objects   
 floatingobjects[j]:applyForce( forceX,ForceY)  
 end  
end  
  
Runtime:addEventListener( "enterFrame", windforce )  

You can manipulate this as you wish, e.g make the force*math.ran(1,10) to make some wind blast or something…

[import]uid: 162464 topic_id: 30066 reply_id: 120391[/import]

I more had in mind:
a) a fan blowing wind & visually showing the wind with particles.
b) but then in terms of the effect on floating objects the objects would be impacted by the wind both:
c) based on distance from fan and
d) how on-axis the object is to the fan, but also
e) the fan could move direction

So based on the last (e) this is where the forces on the object (when they hit etc) is pretty much based on when & how many wind effect particles that hit them. The concern I had was whether that would make sense or not to have lots of small physics enabled particles from a performance point of view. Hope this makes sense.

[import]uid: 140210 topic_id: 30066 reply_id: 120394[/import]

Im a bit tired, be ye it makes sense :wink:

Hmm, if you want visual showing the wind, then you might as well also use them as “push” objects - so they transfer their energy on collision. I really don’t have any idea of how many wind objects you can have in this case :confused: But i cant think of any other ways to do it, particularly when you need to show the wind…

[import]uid: 162464 topic_id: 30066 reply_id: 120398[/import]

I agree with Zwonkie, if you need to show the wind using some kind of particle effect, then you might as well use them as physical colliders that push the objects they hit with a very slight force (use applyForce, not impulse).

Your wind particles could also be sensors, not “solid” objects. When they hit something like a leaf, your collision function compares the X and Y differences (I wrote a post about this just a few days ago) and you apply the proper fractional, directional force.

If performance is bogging down, you could use 2 emitters that behave similarly in direction, speed, etc. but one emits fewer particles than the other… and those are the physical ones. The other emitter emits those for the visual look of the wind, and more of them.

Brent [import]uid: 9747 topic_id: 30066 reply_id: 120447[/import]

thanks guys

@Brent - re “Your wind particles could also be sensors, not “solid” objects” - this is mainly to minimize performance impacts is it Brent? i.e. I’m guessing sensors “cost less” than physical bodies colliding?

Like the idea too about 2 emitters. Actually the 2nd one could even be invisible and it’s limited particles it sends out invisible too… [import]uid: 140210 topic_id: 30066 reply_id: 120525[/import]

Hi Greg,

I actually didn’t clarify that very well. When I was saying that the “physical” wind particles could be sensors, I was thinking that their collision would be handled with a custom function that applied force to the “leaf” in question, instead of just relying on solid Box2D collision forces to push the leaf. It actually makes the whole scenario a bit more complex, but it might also yield a far more realistic-looking simulation. The wind particles, upon collision, would be compared in X/Y differences compared to the leaf, then you’d apply a very slight force based on this calculation, to push the leaf slightly away.

I discussed this method in my posting here, scroll down just a bit on the page:
http://developer.coronalabs.com/forum/2012/08/14/actions-collisions

Hope this makes sense, it’s combining two separate forum posts but the end purpose is fairly similar.

If this seems overly complicated, you could try just making the particles “solid” (not sensors) and turning the density on them way down, so they would only have a subtle effect on the leaf. The snag there is that the particles would then bounce off the leaves, potentially hitting other leaves if you had many in the path of the wind.

Brent
[import]uid: 9747 topic_id: 30066 reply_id: 120528[/import]

thanks Brent - I’m starting to play with these ideas now - outcomes can be kind of funny at times :slight_smile: I can see now (with the options up my sleeve) it’s a matter of trial and error with the options… [import]uid: 140210 topic_id: 30066 reply_id: 120529[/import]