Author Topic: Get is facing an object  (Read 314 times)

Legacy_Nebril2

  • Full Member
  • ***
  • Posts: 104
  • Karma: +0/-0
Get is facing an object
« on: January 09, 2015, 03:47:02 pm »


               

Hi all!


 


 


Im creating a cannon wich, when used, fires the first object in front of him, you can rotate the cannon. 


 


But im having a hard time trying to get the first object the cannon is facing, how do you get if an object is facing another?


 


I imagine that is with getfacing() wich its not relative to the target, and getfacingfromlocation() wich somehow always returns 90 but i cant figure out how...


 


Another idea i tried is getting the first object in a spellcylinder shape... but this is very odd, and its always in the same place no matter wich rotation the cannon have. 


 


Thank you '<img'>



               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Get is facing an object
« Reply #1 on: January 10, 2015, 12:47:01 am »


               It depends. Does the target have to be exactly in line of fire, or can they be anywhere in an arc of fire?

Either way, you can use LineOfSightObject() to check that there are no static obstacles in the way.

Do you care how big the target is?
               
               

               
            

Legacy_Proleric

  • Hero Member
  • *****
  • Posts: 1750
  • Karma: +0/-0
Get is facing an object
« Reply #2 on: January 10, 2015, 10:48:45 am »


               Here's a simple solution for the arc of fire case:
 
int GetIsTarget(object oGun, location lTarget)
{
  float ARC _OF_FIRE = 5.0;  // Target can be hit if it is within -5 to +5 degrees of the line of fire (for example)
  vector vFacing     = GetPositionFromLocation(lTarget) - GetPosition(oGun);

  vFacing.z = 0.0;
  return (fabs(VectorToAngle(vFacing)) <= ARC _OF_FIRE);
}
ignoring line of sight and target size.

Without modification, this means that a wisp at 100m is more likely to be hit than a dragon at 10m, even if there is a wall in the way.
               
               

               
            

Legacy_Nebril2

  • Full Member
  • ***
  • Posts: 104
  • Karma: +0/-0
Get is facing an object
« Reply #3 on: January 10, 2015, 04:25:39 pm »


               

Yes, i learned something about vectors and so... and i could do it in a similar way you pointed '<img'> thank you!


 


 


And about the size, it doesnt matter cause the canon fires a fireball wich explodes in the target location damaging everyone near. 


               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Get is facing an object
« Reply #4 on: January 12, 2015, 07:30:51 am »


               


Here's a simple solution for the arc of fire case:

 



int GetIsTarget(object oGun, location lTarget)
{
  float ARC _OF_FIRE = 5.0;  // Target can be hit if it is within -5 to +5 degrees of the line of fire (for example)
  vector vFacing     = GetPositionFromLocation(lTarget) - GetPosition(oGun);

  vFacing.z = 0.0;
  return (fabs(VectorToAngle(vFacing)) <= ARC _OF_FIRE);
}

ignoring line of sight and target size.


Without modification, this means that a wisp at 100m is more likely to be hit than a dragon at 10m, even if there is a wall in the way.

 




 


Not quite.   This assumes that the line of fire is due East, and it will only hit targets up to 5 degrees North of East. (Targets within 5 degrees South of East will be reported with an angle from 355 to 360).  Also setting the z component to zero is unnecessary as VectorToAngle() ignores it.


 


Here is how it should be done



int GetIsTarget(object oGun, location lTarget, float fConeAngle = 10.0)
{
vector vDirection = GetPositionFromLocation(lTarget) - GetPosition(oGun);
float fFacing = GetFacing(oGun);
return (fabs(180.0 - fabs(VectorToAngle(-1.0 * vDirection) - fFacing))) <= fConeAngle/2;
}