View Single Post
  #10  
Old 07-07-2006, 07:02 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
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 onMouseDownbutton )
  {
  
gravity 0.8;
  
temp.power 1;

  
temp.maxdist = ( (temp.power*20) ^ ) / (gravity 20);
  
temp.dist = ((mousex player.x)^+ (mousey player.y)^2)^0.5;
  if ( 
temp.dist temp.maxdist )
    
temp.dist temp.maxdist;

  
temp.zangle arcsintemp.dist * (gravity*20) / ( (temp.power*20) ^ 2) ) / 2;
  if ( 
button == "double" )
    
temp.zangle = (pi 2) - temp.zangle;

  
temp.getanglemousex 1.5 player.xmousey 2  player.);
  
shootplayer.x,player.y,player.2temp.atemp.zangletemp.power"arrow","");
  }

function 
arcsin)
  { 
// Missing arcsin function, so I made one myself!
  
temp.step 1000;
  for ( 
0abs(i); += temp.step )
    
temp.sum += (/ (j^2)^0.5) * temp.step ;
  return 
temp.sum;
  } 
=] I hope this solves a lot of anguish.
Reply With Quote