Page 1 of 1

Mob looking/heading angle relative to me

Posted: Thu Jul 03, 2014 8:26 pm
by Vayeco Dynn
Want to know whether or not a mob is looking at you? Headed in your direction? Headed away from you? This collection of subs will tell you what angle the mob is looking at relative to you, with 0.00 being directly at you and 180.00 being directly away from you. There's a full 0-360 degree version and a normalized 0-180 degree version (a little more practical for most applications). Hint: 90 degrees means they're looking perpendicular to you, not quite at you or away from you.

Code: Select all

#turbo

Sub Main

   /call MobLookNormalized ${Target.ID}

/return



|--------------------------------------------------------------------------------
|SUB: Angle from 2 points
|--------------------------------------------------------------------------------
Sub SlopeToAngle(float P1X, float P1Y, float P2X, float P2Y)

	/declare Denominator float
	
	/varcalc Denominator ${P2X} - ${P1X}
	
	/if ( ${Math.Abs[${Denominator}]} < 0.01 ) {
	
		/return 0
	
	}
	
	/return ${Math.Atan[${Math.Calc[(${P2Y}-${P1Y})/(${P2X}-${P1X})]}]}

/return

|--------------------------------------------------------------------------------
|SUB: Angle a mob is looking relative to Me
|--------------------------------------------------------------------------------
Sub MobLook(float SpawnID)

	/call SlopeToAngle ${Me.Y} ${Me.X} ${Spawn[${SpawnID}].Y} ${Spawn[${SpawnID}].X} 
	/declare MobAngle float ${Macro.Return}
	
	/if ( ${Math.Calc[${Me.Y} - ${Spawn[${SpawnID}].Y}]} < 0 ) /varcalc MobAngle ${MobAngle} + 180
	
	/if ( ${MobAngle} < 0 ) /varcalc MobAngle ${MobAngle} + 360
	
	/declare Result float ${Math.Abs[${Math.Calc[${MobAngle} - ${Spawn[${SpawnID}].Heading.DegreesCCW}]}]}
	
	/echo Mob is looking: ${Result} relative to Me (${MobAngle} vs ${Spawn[${SpawnID}].Heading.DegreesCCW})
	/return ${Result}

/return

|--------------------------------------------------------------------------------
|SUB: Angle a mob is looking relative to Me (normalized from 0-180)
|--------------------------------------------------------------------------------
Sub MobLookNormalized(float SpawnID)

	/call MobLook ${SpawnID}
	/declare Result float ${Macro.Return}
	/if ( ${Result} > 180 ) {
	
		/varcalc Result 360 - ${Result}
	
	}
	
	/echo Mob is looking: ${Result} relative to Me (normalized)
	/return ${Result}
	
/return

Re: Mob looking/heading angle relative to me

Posted: Sat Jan 17, 2026 12:48 am
by xyilla

Re: Mob looking/heading angle relative to me

Posted: Sat Jan 17, 2026 12:49 am
by xyilla

Re: Mob looking/heading angle relative to me

Posted: Sat Jan 17, 2026 12:50 am
by xyilla

Re: Mob looking/heading angle relative to me

Posted: Sat Jan 17, 2026 12:52 am
by xyilla

Re: Mob looking/heading angle relative to me

Posted: Sat Jan 17, 2026 12:53 am
by xyilla

Re: Mob looking/heading angle relative to me

Posted: Sat Jan 17, 2026 12:55 am
by xyilla

Re: Mob looking/heading angle relative to me

Posted: Sat Jan 17, 2026 12:56 am
by xyilla

Re: Mob looking/heading angle relative to me

Posted: Sat Jan 17, 2026 12:57 am
by xyilla

Re: Mob looking/heading angle relative to me

Posted: Sat Jan 17, 2026 12:58 am
by xyilla

Re: Mob looking/heading angle relative to me

Posted: Sat Jan 17, 2026 1:00 am
by xyilla