I was just wondering what type of mathematical computations/physics I need to know for determining a projectile's path and trajectory.
Printable View
I was just wondering what type of mathematical computations/physics I need to know for determining a projectile's path and trajectory.
the x and y initial position of the bullet
the speed
the path it will travel through either x and/or y
the destination of the bullet
and the condition the will trigger the bullet
to do this all you need is trig...
M
............./|
.........../..|
........./....|
......./......|Y
...../........|
O /A_____|
X
take this badly drawn ascii triangle were 'O' is the origin of the shot 'M' where the aimer/mouse is and 'A' is the angle.
what you need to do is find 'A'
to do this you use
atan2(Y,X)
(or if its based of a characters rotation use the characters rotation as A)
then to get the projectile to move:
Math.sin(iAngle * (Math.PI/180))
this will give you the amount you need to increment the x value by every frame
Math.sin(iAngle * (Math.PI/180))
for the y increment:
Math.cosn(iAngle * (Math.PI/180)) *-1
so all up (pretend that this is based off char rotation and the
of course you realise that you will need to do that properly but thats the general gist of that.Code:
addEventListener(Event.ENTER_FRAME,eFrame)
addEventListener(MouseEvent.MOUSE_DOWN, shootOn);
function eFrame(evt:Event){
projectile .x+=xInc
projectile .y+=yInc
}
function shootOn(evt.MouseEvent){
var xInc:Number = Math.sin(charRotation* (Math.PI/180))
var yInc:Number = Math.cos(charRotation* (Math.PI/180)) * 1;
}
for other things like gravity just do somthing like
for bouncing projectliesCode:
yInc+=gravity
i hope that helps i will once again say that it is all really rough so dont dig into me for that its just there to give you an idea of what to doCode:
if (projectile.y == ground){
yInc = -yInc * bounceDecay // 0.4 or something like that
}
Thank you, buk. :)