Fastest way to find if and what actor player is looking at?

Post » Mon Nov 19, 2012 11:06 am

So, the topic title explains it pretty well... I want to find with a script if the player if facing an actor (ANY actor, not just an actor I already know the ID of), and if so, who it is. I'd like to be able to do the same thing for NPCs as well, but it's more important for the player. And I'd like it to take less than 20 ms, but something higher would be acceptable if less is impossible. 100+ ms is unacceptable though. Also needs to reliably return the closest actor that is being looked at by the player, if there are many in the same direction.

So... the first idea I have is to cast an invisible (and very fast) projectile spell directly forward, check who/if the target actor is in the spell effect script, then send the value back to the original script somehow.

I have some questions about this though:

(1) The wiki says the cast function will cast the spell in a "default direction" if a target is not specified. Is this always the direction that the player is facing?
(2) If not, what is the best way to cast it in that direction? My idea is to place a marker object in front of the player's view and cast at that, but the math + placement functions seem like they'd take a lot of extra time.
(3) What is the best way to give the spell's target actor back to the original script? The things I can think of are: have form list property of both scripts, and temporarily put the actor into it, or use a global variable or some dummy actor and put the formID in there. Since it only needs to be accurate for less than a second, I'm not too worried about the formID changing or anyway, but I'm worried about how to know when the value is ready to be accessed? It seems kind of silly to just loop at 1ms intervals or something to check if the value has been set yet...
User avatar
priscillaaa
 
Posts: 3309
Joined: Sat Dec 30, 2006 8:22 pm

Post » Mon Nov 19, 2012 11:28 am

Nobody? Bumping I guess... :sad:

I'll begin testing with the ideas I have for now though.
User avatar
lilmissparty
 
Posts: 3469
Joined: Sun Jul 23, 2006 7:51 pm

Post » Mon Nov 19, 2012 1:42 pm

So, the way I would do this (granted there are other ways) I would create a new quest called GetLOSNPC with a single optional Alias. Fill Type: Find Matching Reference [X] In Loaded Area. [X] Closest. And set the criteria accordingly.

Use Aliases [X]
GetLineOfSight [Alias: SomeAlias] == 1
Run On [Player]

Maybe add some other filters like... GetCombatState = 1 && ... GetPlayerTeammate == 0

Then, from your code, when you need to find a target:

GetLOSNPC.Start()
ReferenceAlias npc = GetLOSNPC.GetAlias(0) As Reference Alias
if (npc && npc.GetActorRef())
;; do stuff
else
;; No one meeting criteria at this time
endif
GetLOSNPC.Stop()

You have to stop and start the quest around the check because aliases are only filled when started. But what isn't clear to me is if you want this as a single fire function you can call or an "Event". The solution you propse above with a projectile implies you want a single fire method.
User avatar
Rex Help
 
Posts: 3380
Joined: Mon Jun 18, 2007 6:52 pm

Post » Mon Nov 19, 2012 11:16 am

You have to stop and start the quest around the check because aliases are only filled when started. But what isn't clear to me is if you want this as a single fire function you can call or an "Event". The solution you propse above with a projectile implies you want a single fire method.

Either way would work, I think. Thanks for the suggestion, I will try it.
User avatar
Alex [AK]
 
Posts: 3436
Joined: Fri Jun 15, 2007 10:01 pm


Return to V - Skyrim