c++ – How do I create particles that react to the participant and enemies?

c++ – How do I create particles that react to the participant and enemies?

[ad_1]

It is a cool thought. You’d want some type of diffusion gradient round your ship. There are three bodily fashions I can consider that you may want:

  1. You need it to appear virtually prefer it’s a liquid medium, the place the stress gradient rebalances, i.e. as soon as you’ve got handed some particles, they transfer again into your wake (like water behind a ship). On this occasion, the particle’s positions are absolute, and it is solely their relation to the participant which briefly modifies their rendering place. It is a bit like once you cross a thick magnifying glass over issues, and the diffraction appears to make them transfer — however solely till you progress the glass away. On this case, your ship is the glass.

  2. If you would like them to maneuver away from the ship, and proceed shifting as soon as they’ve moved. That is like commonplace physics in typically empty house the place there are not any (or very small) stress gradients.

  3. You wish to transfer the particles away from the ship swiftly because it approaches, as in (1) and (2), however as soon as the ship is gone, the particles will slowly re-balance themselves to be equidistant in your wake.

Widespread to all three options: you might want to have a diffusion area that strikes together with your ship. On this instance, we’ll make it round. You then detect vector — name it v1 — between the ship and every particle inside that area. Push your particle away alongside that vector. How strongly you will push it away will depend upon its distance from the ship: use 1 - v1.magnitude. This components provides you with a linear energy, nevertheless you can modify it to make use of one thing else like a round energy curve that diminishes in energy towards the perimeters. This may give it extra of a glance as if there is a spherical quite than round stress gradient across the ship.

For resolution 1: All you now do is modify the render place of that particle (that’s, the sprite place) on each render replace, by this vector. Since you’re doing it this fashion, that is purely a rendering impact and has no impact on the particle’s precise world place. So that you add the world place to the render offset (v1) and also you now have properly displaced particles as you progress previous, towards or beside them, and easily reverting particles as you cross by (behind you).

For resolution 2: As an alternative of simply making use of v1 to the view place, apply it on every logic replace, to the particle’s place. So, p1.place += v1. So that you’re making use of an accelerative drive to the particle, which interprets into velocity. You may in all probability need every particle’s velocity to be dampened, in order that they they will step by step decelerate and are available to a halt as soon as you’ve got handed. You may see how this resolution will end in bunched-up particles in your nebula as a result of they will by no means re-diffuse. Not very sensible, I am certain, since nebulae have stress gradients inside them, irrespective of how weak in actuality.

For resolution 3: Identical as (2), however on this case you are going to must re-diffuse your particles. To do that simply is a little bit of a brute-force strategy, however since these are solely particles and thus eye-candy, you in all probability needn’t cowl an enormous space of curiosity (in all probability solely a radius of playerPosition + maxPlayerSpeedPerTick, or no matter rectangular space circumscribes that, for logic functions). Every particle will apply a drive on one another particle throughout the space of curiosity. They’re going to apply forces based mostly, as soon as once more, on their distances from each other. Calculate all inter-particle forces in a single sweep throughout the realm of curiosity after which apply all of the forces in a single sweep. Lastly, just be sure you solely carry out this inter-particle drive processing on particles which have zero velocity. And as soon as any given particle reaches some minimal velocity, lower it is velocity vector to zero, in order that it is now not utilizing up processor time.

There are all types of diffusion formulae, and so forth., on the market, however I believe on this case, a easy resolution works finest.

[ad_2]

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply