Jump to content

Custom Companion Move to Player


RBRoAB

Recommended Posts

I am trying to make a custom NPC move to player when they get too far behind. This is only a problem because the NPC is a Protectron.

Will this work?

 

If GetDead == 0 && GetUnconscious == 0
    if ProtectronREF.getdistance player > 4000
         ProtectronREF.Moveto player
    endif
Endif


End

Edited by RBRoAB
Link to comment
Share on other sites

I am trying to make a custom NPC move to player when they get too far behind. This is only a problem because the NPC is a Protectron.

Will this work?

 

If GetDead == 0 && GetUnconscious == 0
    if ProtectronREF.getdistance player > 4000
         ProtectronREF.Moveto player
    endif
Endif


End

 

Yes, that will work, but I'd put a distance and the x,y,z coordinates in that move to as well so the protectron moves to the player but shows up behind the player. I assume, in my scripts that move Willow to the player routinely while she's following the player, that the player is going about his business and probably looking forward and/or moving forward, so that when she is moved to the player in the script that putting her behind him is the best way to do it (so the player doesn't see it happen). When she moves to the player for other reasons I put her to the side or in front of the player.

 

Edit: If you can fire your companion you might want that and waiting to be conditions as well.

Link to comment
Share on other sites

Oh, THAT'S why when Veronica's on the other side of the bleeding Mojave getting stuck on a broken NavMesh or something Willow's right where she's supposed to be, two metres behind me and one to the right, putting .45-70 Gov't slugs in the heads of Deathclaws and Legion Assassins.
Link to comment
Share on other sites

Thanks for the help guys! I mean, I'd do that if I could...I literally spent an hour coming up with this haha. I'm new to scripting, but getting better.

 

So how would you script in x,y,z coordinates?

 

Wiki says: Object.MoveTo MarkerID:ref OffsetX:float OffsetY:float OffsetZ:float

 

So you have some geometry to do.

 

Establish a distance you want your protectron from the player. If you want him to pop directly behind the player, you just call player.getAngle X and then the sin and cos functions to get your x and y offsets.

 

Otherwise... it gets trickier. I'd have to look at axes and sketch some trig to work it out.

Link to comment
Share on other sites

Well that escalated quickly.

If I wanted him to come up right behind me, like a few feet back maybe, what would that look like?

an example of the script would be nice

and what variables need defining

 

Directly behind you, about six feet back, is ~128 game units. So.

 

the math looks like this:

Offset:X == sin ((player.getAngle X) * 128)

Offset:Y == cos ((player.getAngle X) * 128)

 

You want him behind the player, so multiply them both by -1.

 

You probably want him facing the same direction as the player, so you'll want to call setAngle X player.getAngle X

 

The final thing might look something like this:

 

float fPlayerAng
float fX
float fY

#BlockType#

If GetDead == 0 && GetUnconscious == 0
if ProtectronREF.getdistance player > 4000
	Set fPlayerAng to player.getAngle X
	Set fX to -128 * (sin fPlayerAng)
	Set fY to -128 * (cos fPLayerAng)
	ProtectronREF.Moveto player fX fY 32 ;A height boost in case the player's moving downhill.
	ProtectronREF.SetAngle X fPlayerAng
endif
Endif


End

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...