(Tutorial) Make an NPC walk forward without heavy math

Post » Tue Jan 26, 2016 1:34 pm

Hello everyone. This may seem like a silly thread to make, but believe it or not, there's no simple function in Papyrus to make an actor walk forward. The only way known before was to use an invisible actor, and move them in front of the actor wishing to make walk. Problem is, MoveTo is relative to the Actor's position in the cell, not their local location. So you had to use Sin() and Cos() on the actor, then move the invisible reference, then use KeepOffsetFromActor() from the real actor to the dummy ref. It was very math heavy with using angles and math slowed Papyrus down a lot. I used it in my Couch Co-Op Mod for ver 0.1, but after finding this solution out, I replaced the bad code with this in 0.2+.



Turns out the simple way to make an Actor to move forward is:



Actor Property YourActor Auto

Event OnSomeEvent()
YourActor.KeepOffsetFromActor(YourActor, afOffsetX = 0, afOffsetY = 100, afOffsetZ = 0, afCatchUpRadius = 150, afFollowRadius = 0) ;Run FORWARD
EndEvent

Event OnSomeOtherEvent()
?YourActor.ClearKeepOffsetFromActor()
EndEvent

The Actor will technically keep an offset from himself, so using a y value of 100 as seen here is forward, -100 would be backwards. 100 from my testing appears to be full run speed. Lower values will result in slower movement. Values higher than 100 still result in a full run speed.



Left and Right are x, so you can use :



YourActor.KeepOffsetFromActor(YourActor, afOffsetX = 100, afOffsetY = 0, afOffsetZ = 0, afCatchUpRadius = 150, afFollowRadius = 0) ;Run RIGHT

For moving Right, and -100 would be left.



You can also combine the afOffsetX and afOffsetY value to induce diagonal movement:



YourActor.KeepOffsetFromActor(YourActor, afOffsetX = 100, afOffsetY = 100, afOffsetZ = 0, afCatchUpRadius = 150, afFollowRadius = 0) ; Run FORWARD AND RIGHT


Edit: So it appears that SetActorValue("speedmult", yournumber) wasn't even needed. Further testing shows that just setting the x, or y values higher or lower satisfies the same result. Post fixed accordingly.

User avatar
Julia Schwalbe
 
Posts: 3557
Joined: Wed Apr 11, 2007 3:02 pm

Post » Tue Jan 26, 2016 9:52 am

What about using packages and markers?

User avatar
Adrian Morales
 
Posts: 3474
Joined: Fri Aug 10, 2007 3:19 am

Post » Tue Jan 26, 2016 7:54 pm


Well there are a couple of differences here:



  • Using packages with still make the NPC path to the location, so they'll walk around rocks, move around objects, etc. The scripts I posted will just make the actor run forward, even continually into a wall.

  • Packages and markers cant be edited via script

User avatar
Amy Masters
 
Posts: 3277
Joined: Thu Jun 22, 2006 10:26 am

Post » Tue Jan 26, 2016 10:38 am

KeepOffsetFromActor was a little known function til it revealed to allow side by side walking between two actors. Powerful function.

User avatar
Mario Alcantar
 
Posts: 3416
Joined: Sat Aug 18, 2007 8:26 am


Return to V - Skyrim