# Sprites and particles complex motion (2D)

This topic is 3587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm into making a 2D game, and I have a question about 2D motion of things on screen. My question is how do I create particles or sprites that move on paths that are not straight or 45 degrees, but rather curved and irregular. Here is an example of what I mean:
The boss shoots swirls of particles that dont just go straightforward but change direction. Im guessing there is a lot of complex math involved. I want, for example, to have particles fly out and behind the main char when he casts a spell, and then in a curved motion speed up towards the enemy. I know how to make basic physics like faling and bouncing, but I dont get this. Could someone point me in a good direction?

##### Share on other sites
Nothing super complicated there. Most of those bullets just go straight but they get sprayed out in various patterns.

A few ideas:
1. A particle emitter that sprays like a lawn sprinkler
vec2 ParticleEmitter::getNextParticleVelocity(){    _angle += _delta;    if ( (_angle >= _maxAngle) || (_angle < _minAngle) )        _delta = -_delta;    return vec2(cos(_angle),sin(_angle));}

2. A particle that 'seeks' its target. (Do physics and always point the particle towards the target)

3. A particle that does motion relative to its path (which is presumably a seeking path or even just a straight line).

The relative motion could be a circle:
void Particle::update( float time ){    ...  // move the pathPosition    _offsetPosition = vec2(cos(time*_freqMultiplier),sin(time*_freqMultiplier));    _position = _pathPosition + _offsetPosition;}

Or it could be a lissajous curve (http://en.wikipedia.org/wiki/Lissajous_curve)
_offsetPosition = vec2(cos(time*_freqMultiplierA),sin(time*_freqMulitplierB));

Or it could be simple sinusoidal offset (here we want to align things normal to the path we're following):
vec2 normal = vec2(_velocity.y, -_velocity.x);normal.Normalize();_offsetPosition = normal*(_magnitude*sin(time*_freqMultiplier));

It could even be smoothed random noise.

You just have to be a bit creative and experiment. =)

##### Share on other sites
Thank you very much. Exactly what I was looking for, and I also found this: http://en.wikipedia.org/wiki/Rose_curve

##### Share on other sites
It looks like you've already found what you're after. Just in case, here's a tip for structuring your algorithm: There are basically two different non-linear ways you can think about determining a particle's path:

1 - Predetermined: there is a curve or equation that determines the particle's location as a function of time. If you are interested in defining a specific set of curves, consider Bezier splines: there are simple to define and calculate, and are relatively simple to understand.

2 - Dynamic: the path of your particle depends on other moving elements around the sprite. The sprite may accelerate towards a target, or be placed in a gravity / electric field from other object masses / charges. There are a number of ways to model different forces, but since you're calculating them frame-by-frame, this can produce some more interesting effects in the long run. You might want to look at some simple physics models to base off which you can base your equations. So long as you calculate motion from forces and accelerations, you can ensure that your sprites will have reasonably-realistic motion.

Good luck!

##### Share on other sites
Thanks for the useful info

1. 1
Rutin
69
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633431
• Total Posts
3011834
• ### Who's Online (See full list)

There are no registered users currently online

×