Alright... I just made something for this... Anyhow... I was working on Projectiles for Relic, and I have encountered problems with the shoot as well...
After several hours of working on it... I found out the that gravity laws don't work. The reason for this is that the verticle speed, or the horizontal speed... Aren't in tiles per second, but rather in tiles per 0.05 seconds. This implies that if you had a power of 1, and you're going maximum distance, you go 20 tiles, rather than 1 tile..
distance = (v^2 * sin(2 * zangle ) ) / gravity
So when Power == 1, and gravity == 1... Distance would give 1...
But, if you make adjustments to the values, and treat them as per 0.05 seconds... Everything falls into place:
Final Code:
PHP Code:
function onMouseDown( button )
{
gravity = 0.8;
temp.power = 1;
temp.maxdist = ( (temp.power*20) ^ 2 ) / (gravity * 20);
temp.dist = ((mousex - player.x)^2 + (mousey - player.y)^2)^0.5;
if ( temp.dist > temp.maxdist )
temp.dist = temp.maxdist;
temp.zangle = arcsin( temp.dist * (gravity*20) / ( (temp.power*20) ^ 2) ) / 2;
if ( button == "double" )
temp.zangle = (pi / 2) - temp.zangle;
temp.a = getangle( mousex - 1.5 - player.x, mousey - 2 - player.y );
shoot( player.x,player.y,player.z + 2, temp.a, temp.zangle, temp.power, "arrow","");
}
function arcsin( i )
{ // Missing arcsin function, so I made one myself!
temp.step = i / 1000;
for ( j = 0; j < abs(i); j += temp.step )
temp.sum += (1 / (1 - j^2)^0.5) * temp.step ;
return temp.sum;
}
=] I hope this solves a lot of anguish.