Jump to content

How to make Player use PathToReference?


Recommended Posts

Hello.

 

Maybe this is not possible. I am trying to use Papyrus to make the Player character walk to a specific position determined via Papyrus.

 

This is the code I'm testing with:

        ObjectReference f = PlayerRef.PlaceAtMe(marker)
	f.waitfor3dload()
	
	f.SetAngle(0.0, 0.0, f.GetAngleZ())

	float cX = f.GetPositionX()
	float cY = f.GetPositionY()
	float cZ = f.GetPositionZ()

	float nX = cX + 200
	float nY = cY + 200
	float nZ = cZ

	f.SetPosition(nX, nY, nZ)

	Debug.Notification("Current: " + cX + ":" + cY + ":" + cZ)

	Debug.Notification("New: " + nX + ":" + nY + ":" + nZ)

	Debug.Notification("WalkingTo: " + PlayerRef.PathToReference(f, 0.5))

When it runs, I can see that the marker object does get created and placed properly. But, the player character doesn't walk to it.

 

Any ideas?

 

Do I need to disable player controls first? Does this even work on the player character or NPC only?

 

Thank you for any help.

Edited by dagobaking
Link to comment
Share on other sites

You must create an InputEnableLayer which will be present during the whole thing you're planning, say it will be declared in a quest (otherwise it won't work properly). Then you need to DisablePlayerControls() and SetPlayerAIDriven(). Forcing game to EvaluatePackage() on Player right after that might be a good idea.

 

P.s. your code doesn't mention anything about player traveling at first glance, though you might be running a package already, I don't know ofc.

Link to comment
Share on other sites

You must create an InputEnableLayer which will be present during the whole thing you're planning, say it will be declared in a quest (otherwise it won't work properly). Then you need to DisablePlayerControls() and SetPlayerAIDriven(). Forcing game to EvaluatePackage() on Player right after that might be a good idea.

 

P.s. your code doesn't mention anything about player traveling at first glance, though you might be running a package already, I don't know ofc.

 

Thank you for these notes!

 

This code is within a script attached to a quest. Is that what you mean by declared in a quest? Or, is there other set-up needed using the CreationKit quest architecture? (I have seen character movement controlled exclusively in this way. But, I am hoping to handle it with just code if possible.)

 

What I would like to do is to simply have a function in my quest script that, when called, will make any character (NPC or Player) walk to a specific coordinate and angle and report when done.

 

You mention "player traveling". Is PathToReference for characters traveling long distances? I'm just trying to have the characters move around to specific positions within a small area: the area visible to the player in the moment.

Link to comment
Share on other sites

Hmm, I understood. Yeah, if that's the script attached to a quest which is active (running) and you call functions from it (for example in the papyrus stage segment by secting kmyQuest), everything should be fine. That way it works for me at least, not saying other compounds can't be used, but this way it works for sure.

 

 

 

DLtmiNw.png

 

nPGu2vr.png

 

uitNB8p.png

 

 

 

I never tried PathToReference() to be honest, so suit yourself here. In your piece of code you don't call PathToReference() if you ask me; I'm not sure if that appellation in Debug.Notification should actually make Player do something. Pay attention to what I wrote about Disabling Controls and pics. Try this PathToReference() first, if it works with NPCs, then it's a question of not taking control from the player.

 

Another way to make an actor walk, the variant I would start with, not knowing PathToReference() function exists, is to create an empty ReferenceAlias (flagged Optional) that has a Travel AI package on it. Then it's exactly what I told you at the beginning: create an InputEnableLayer, DisablePlayerControls() and SetPlayerAIDriven() - if player. And then just EvaluatePackage() on thit alias to force the game re-load the stack of packages on it. **In this case, after you calculate that "f" position, simply move the destination XMarkerHeading (from Travel package) to this point. No need to spawn it, you can have it in a... say tech cell, pre-arranged in CK.

Edited by werr92
Link to comment
Share on other sites

 

Another way to make an actor walk, the variant I would start with, not knowing PathToReference() function exists, is to create an empty ReferenceAlias (flagged Optional) that has a Travel AI package on it. Then it's exactly what I told you at the beginning: create an InputEnableLayer, DisablePlayerControls() and SetPlayerAIDriven() - if player. And then just EvaluatePackage() on thit alias to force the game re-load the stack of packages on it. **In this case, after you calculate that "f" position, simply move the destination XMarkerHeading (from Travel package) to this point. No need to spawn it, you can have it in a... say tech cell, pre-arranged in CK.

 

Thank you!

 

It turns out that the only additional line of code that I needed was "Game.SetPlayerAIDrive()".

 

For reference, this is the code that worked:

 

Function walkTo()

Game.SetPlayerAIDriven()

ObjectReference f = PlayerRef.PlaceAtMe(marker)
f.waitfor3dload()

f.SetAngle(0.0, 0.0, f.GetAngleZ())

float cX = f.GetPositionX()
float cY = f.GetPositionY()
float cZ = f.GetPositionZ()

float nX = cX + 200
float nY = cY + 200
float nZ = cZ

f.SetPosition(nX, nY, nZ)

PlayerRef.PathToReference(f, 0.5)

Game.SetPlayerAIDriven(false)

EndFunction
Link to comment
Share on other sites

Yes. The information from Werr92 is spot on. Here is also a living, breathing, demonstration of an AI controlled player. https://www.nexusmods.com/skyrim/mods/27738/

Check the comment section for more tid-bits of info.

 

Thank you for this.

 

I have the walking function down great now. The only issue is that the characters walk to the marker and then just stop facing the direction they were walking.

 

Ideally, in addition to walking to the marker, they would turn to face the same direction as the marker.

 

I tried using SetAngle. But, that just teleports the Actor to the given angle. And if it's the player, it actually turns the screen black momentarily.

 

Any ideas on how to have the actor turn naturally to face the angle of the marker? (Hopefully, with code only so I can avoid the atrocious package system.)

Link to comment
Share on other sites

Thinking about this. I could use some trigonometry to have the character walk to point A and then place a point B a tiny distance away but at the right relative angle to force the player to turn like I want.

 

But, there really should be a more direct way...?

Link to comment
Share on other sites

I went ahead and made the trigonometry version. Kind of works. But, isn't very precise. It seems that the engine counts the pathing as a success if the player just gets close to the marker.

 

Would love to learn about a more precise method if anyone knows.

Link to comment
Share on other sites

Do you mind if I ask what you've found to be atrocious about the package system? I've also had a LOT of trouble with them over the last few months and I was starting to think I was crazy! =)

Link to comment
Share on other sites

  • Recently Browsing   0 members

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