View Single Post
  #2  
Old 09-17-2011, 05:43 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
Determining the angle between two objects.

1. Calculate the Delta between the Origin and the Target
2. Use getangle to return the angle based on the Delta

Note: Delta = Final - Initial

PHP Code:
function getTargetAngle(origintarget) {
  
// Calculate Delta X and Y
  
temp.delta_x target.origin.x;
  
temp.delta_y target.origin.y;
  
// Return Angle Based on Delta
  
return getangle(temp.delta_xtemp.delta_y);

The above will return the correct angle towards the target object.

If you want the Graal direction, you can just swap out getangle with getdir and it'll return a number in |0,3|.

Also:

PHP Code:
function onWeaponfired() { 
  if (
this.rocketfired == "1") { 
    
this.rx mousex
    
this.ry mousey
    
onTimeout(); 
  } 
  
this.rocketfired 1

Would require you to fire it twice to actually fire it, and even then you could fire it as much as you wanted to mess it up while the rocket is in motion. You want to do something like this:

PHP Code:
function onWeaponfired() { 
  if (
this.rocketfired == 0) { 
    
this.rx mousex
    
this.ry mousey;
    
this.rocketfired 1
    
onTimeout(); 
  }  

I would also suggest doing:

PHP Code:
function onTimeout() {
  
// other code...
  
if (this.rocketfired == 1setTimer(0.05);

So your script only loops when it needs to.
__________________
Quote:
Reply With Quote