Search code examples
flashactionscript-3flash-cs5

Speed of an arrow


I'm trying to program an arrow flying in the air, but the speed doesn't look well.

But now the arrow moves very slow, here's a sample.

(I know the arrow and the trajectory don't match 100%, it's just a sample.)

//...

var inity0:Number = 50;
var initangle:Number = - Math.PI / 4;
var initvelocity:Number = 100;
var initvx:Number = initvelocity * Math.cos(initangle);
var initvy:Number = initvelocity * Math.sin(initangle);
var currentvx:Number = new Number(initvx);
var currentvy:Number = new Number(initvy);
var initdistance:Number = math.calcDistance(inity0,initvelocity,initangle);

currentvy -= 9.81 / stage.frameRate;
activearrow.x += currentvx / stage.frameRate;
activearrow.y -= currentvy / stage.frameRate;

//...

Any ideas?

EDIT: I've changed the following code:

currentvy -= 9.81 / stage.frameRate * 15;
activearrow.x += currentvx / stage.frameRate * 15;
activearrow.y -= currentvy / stage.frameRate * 15;

And now it looks good, but can someone tell me why I need to do this while in physics it normally would fly 15 times too fast?


Solution

  • Surely, you just need to specify a greater value for initvelocity until you find a speed you consider suitable?

    Edit:

    There's nothing to relate your distances and absolute positions to anything in the physical world. Very little in reality is measured in 'pixels per second'. Your statement currentvy -= 9.81 / stage.frameRate;, if I understand how flash is working (it's been a while, too), is effectively setting the vertical deceleration at 9.81 pixels per second squared (not metres), which is understandably slow. Alternatively, if you consider that your calculations are effectively scaled at 1 pixel = 1 metre, the speed isn't necessarily unreasonable, but you do have an incredibly large bow and arrow!

    You simply need to apply some scale to approximate something 'reasonable'. No real science to it, to be honest.