Make NPC approach the player?

Post » Fri May 27, 2011 11:46 pm

Well, the situation is: a newly placed NPC should approach PC and follow him until PC decides to talk (no ForceGreeting). AIFollow does the trick almost completely... except one thing - the initial NPC position is far enough when PC sees him for the first time and he keeps standing there until PC walks closely enough to him for the AI package to kick in.

Options I have:

1) Simply move the starting position closer to PC so that AI might start working immediately. I would *like* for NPC to approach player from a bigger distance, but I might resort to that unless better options turn up.

2) Leave everything as is and hope that PC will eventually come close by mere chance. Since the rendezvous point is in the open space, this may not be soon. Player might leave not even noticing somebody wants to talk.

3) Make NPC AITravel first to where the player might be standing and only then switch to AIFollow. Slightly better than above, but again, this is an open space and player may go too far in a direction unpredictable while NPC is walking.

4) Make NPC StartCombat player and then StopCombat and switch to AIFollow at a lower distance. Unfortunately, the battle music kicking in will spoil the scene. Unacceptable.

5) ????
User avatar
Cathrine Jack
 
Posts: 3329
Joined: Sat Dec 02, 2006 1:29 am

Post » Sat May 28, 2011 4:50 am

Not sure, I'd try aiactivate player, it should not start battle music, it may be a little tricky to reset when near enough though.

[EDIT]I recalled the source of the aiactivate idea, I saw it in ZI_NPC_Messenger script in Booty.esp (Booty Island) by Jog. That NPC is able to radar-tracking you around half VVardenfell, the only weird thing is that if you are teleporting around and he is far, you may hear a lot of strange "Hey, Wait! Where are you going?" apparently coming from nowhere! :D
Begin ZI_NPC_Messenger; Pirates On Azura's Coast:; The Messenger that starts the quest.; He's created by ZI_Global_NPC_Placer; And follows the player to tell him to report to Socucius Ergalla...short stateshort timerif ( state == 0 )	if ( ( Getdetected player ) == 1 )									; Follow the player		AIActivate player		Forcerun		Say "Vo\R\M\Flw_RM001.mp3" "Hey, Wait! Where are you going?"		set state to 1	endif	Returnendifif ( state == 1 )														; Set a new Waypoint all 60 Frames	set timer to timer + 1											; In case the player tries to run away	if ( timer > 60 )		Say "Vo\R\M\Flw_RM001.mp3" "Hey, Wait! Where are you going?"		AIActivate player		Forcerun		set timer to 0	endif	if ( ( getdistance player )	< 150 )							; When he's near enough, he'll 		if ( ( Getdetected player ) == 1 )							; talk to the player			Clearforcerun			AIWander 2000,5,0,60,40,20,10			set state to 2			Forcegreeting		endif	endif	Returnendifif ( ( Getjournalindex ZI_Pirates_0 ) >= 10 )					; After that he'll vanish	if ( Cellchanged == 1 )										; on next Cellchange...		if ( ( Getlos player ) == 1 )				disable			setdelete 1		endif	endifendifend

User avatar
Paul Rice
 
Posts: 3430
Joined: Thu Jun 14, 2007 11:51 am

Post » Fri May 27, 2011 7:32 pm

how about a compromise between 2 and 3?

have the NPC AITravel between a few points the player is likely to pass near, and then when close enough have the AIFollow kick in.
User avatar
Joie Perez
 
Posts: 3410
Joined: Fri Sep 15, 2006 3:25 pm

Post » Sat May 28, 2011 12:32 am

It could get complicated, but I'd try using AITravel with an update every several seconds. Each time it would re-target the player's current position, also checking that the player hasn't gone too far away or out of the NPC's safe living area.. If it detects close range, then switch to AIFollow.

However, I don't know if you can re-use AITravel when a previous call to AITravel hasn't yet reached it's destination. If that's a problem, then you'd have to calculate shorter trips that can be completed in maybe 10 seconds each. Might be a pain to code that.
User avatar
Lillian Cawfield
 
Posts: 3387
Joined: Thu Nov 30, 2006 6:22 pm

Post » Sat May 28, 2011 6:48 am

It could get complicated, but I'd try using AITravel with an update every several seconds. Each time it would re-target the player's current position, also checking that the player hasn't gone too far away or out of the NPC's safe living area.. If it detects close range, then switch to AIFollow.

However, I don't know if you can re-use AITravel when a previous call to AITravel hasn't yet reached it's destination. If that's a problem, then you'd have to calculate shorter trips that can be completed in maybe 10 seconds each. Might be a pain to code that.

I've tried something similar before (only with AIactivate). The problem I found was the NPC would walk in thw right direction fine, but every two seconds they would 'jerk' upright as their destination was reset.
User avatar
Ella Loapaga
 
Posts: 3376
Joined: Fri Mar 09, 2007 2:45 pm


Return to III - Morrowind