PDA

View Full Version : [AS3] air resistance.


Starky_AS3
09-10-2009, 05:50 AM
Hey,

Im making a archery game and I was just wondering if it was possible to add air resistance to the stage.

All help very much appriciated.

Starky

tango88
09-15-2009, 03:50 AM
Of course.

You'll have a value for the x speed of the arrow like this:

var xspeed=5;

So that when your arrow is moving, you have something like this in your game loop:

arrow.x+=xspeed;

Now define a variable and value for the wind resistance

var wind = .01;

And add it to the loop:

xspeed -=wind;
arrow.x += xspeed;

TomMalufe
09-15-2009, 03:38 PM
wind resistance doesn't really work the way tango88 is explaining it... but it may be good enough for a simple archery game.

Officially air resists more the faster the object tries to move through it. The resistance is not constant. This is what gives us a terminal velocity while falling. The winds resitance builds up more and more till it's force is the same as gravity, thus acceloration stops and velocity becomes constant.

But, you have to think about the movement of the air as well. If the air is blowing against you, that will change the numbers.

To be the most accurate you add to the speed more like this.
var windSpeed:Number = -5;
var airResistance:Number = .01;
var xspeed:Number = 10;
xspeed -= (xspeed+windSpeed)*airResistance;
or something like this. experiment with values

Just remember that air isn't going to resist an arrow very much. But you can exaggerate it anyways for the fun of the game.