Determine Actor in Player's LOS

Post » Mon Jun 27, 2011 9:50 am

I have an animation I am trying to make into an attack Its an idle animation - What im asking is how can you detect any random creature/actor directly infront of the player, I have something along the lines of:

while (Target)	set Target to GetFirstRef 69 0	if(target.getDistance player > 128)		target.kill	endif	     set Target to GetNextRef	loop


Am I on the right track? or is there a much better way?
User avatar
sally R
 
Posts: 3503
Joined: Mon Sep 25, 2006 10:34 pm

Post » Mon Jun 27, 2011 8:34 am

No, that script seems messed up.
You have to declare the target BEFORE looping references:
set Target to GetFirstRef 69 0while (Target)        if(target.getDistance player > 128)                target.kill        endif        set Target to GetNextRefloop

And that is a bit weird. The target will be killed if he is at a distance greater than ( > symbol) 128 units of the player. So effectively everyone will get killed once you enter a cell. I guess it should happen if the target is at a distance less than ( < symbol) 128. And when killed, the target will not add to the player killcount, you have to use target.kill Player for that.
And there is no check to see if the creature is in front of the Player. For that you have to use a condition like:
if Player.GetHeadingAngle target < rightmostangle && Player.GetHeadingAngle target > leftmostangle

Where rightmostangle and leftmostangle are the max and min angles from your field of view between which you consider the target to be 'in front' of you. The center of your field of view is 0 o, and from there extends to 75 o to the right and - 75 o to the left (AFAIK, I'm not very good with orientation). I think values of 15 and -15 are fine.
And I don't know the conditions to check for height (the target could be in your FOV but way over you and the script would still catch it), but you can try with:
if target.GetPos z <= (Player.GetPos z + Player.GetBoundRadius) && target.GetPos z <= (Player.GetPos z - Player.GetBoundRadius)

I'm sure there are more precise ways though.

Finally consider using an array iteration to improve performance:
array_var targetIterref targetForEach targetIter <- GetHighActors	let target := *targetIter	if target.GetDistance Player <= 128 && Player.GetHeadingAngle target < rightmostangle && Player.GetHeadingAngle target > leftmostangle && target.GetPos z <= (Player.GetPos z + Player.GetBoundRadius) && target.GetPos z >= (Player.GetPos z - Player.GetBoundRadius)		target.Kill Player	endifloop

User avatar
Everardo Montano
 
Posts: 3373
Joined: Mon Dec 03, 2007 4:23 am

Post » Sun Jun 26, 2011 9:25 pm

Scratch all of that. From what you are describing, you can simply use 'set target to GetCrosshairRef' to get the thing that the player is looking at when executing the animation, and kill it accordingly.
User avatar
Jake Easom
 
Posts: 3424
Joined: Sun Jul 29, 2007 4:33 am


Return to IV - Oblivion