Scripts / How to make an NPC walk backwards?

Author
Message
fearlesswee
4
Years of Service
User Offline
Joined: 30th Aug 2019
Location: United States
Posted: 29th Jan 2020 05:45 Edited at: 29th Jan 2020 06:01
I'm currently scripting a sort of "VIP" NPC, where an unarmed NPC will follow the player on their adventures, and the player will need to guard them to prevent a game over. However, I've run into a bit of a problem: Sometimes he will follow the player into a building, and will stand in the doorway, blocking the exit! I know it's possible to circumvent this by making every building with multiple exits, but that could cause problems with designing a linear level, and I might not spot every area where the VIP could clog the exit.

Basically, I just need him to walk backwards for a second or two once the player gets close, sorta like the citizens/rebels from Half-Life 2. I've scoured the global.lua file for anything relating to walking backwards, but no luck. How could I go about doing this? (If all else fails I could find a way to get an XYZ position that is a few feet behind the NPC, and have him turn around and walk to that point. In which case, how could I calculate an XYZ position that is behind the NPC?)

EDIT: I would like to point out I'm aware of the "MoveBackward(e,v)" command, but that doesn't really make him "walk" backwards so much as "eerily slide" backwards lol.
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 29th Jan 2020 17:34
So... you already have them moving backward (albeit sliding)? - Yes?
Using stock scripts??
If you're not on stock scripts, and have walking animation in your scripts now,
just turn on walking animation (reverse it) when you do that backward move.

PM
fearlesswee
4
Years of Service
User Offline
Joined: 30th Aug 2019
Location: United States
Posted: 29th Jan 2020 18:33
I'm not 100% sure what you mean by that, there's no animations in the script, it's all in the .fpe of the character. (Which right now as a placeholder is the default "masked soldier" character)

My script is 100% custom and uses the "SetCharacterToWalk(e)" and "SetCharacterToRun(e)" commands to change their "state" and by extension animations/movement speed.

So you're saying that there's some way to manually control animations via Lua, how could I do this? I could still use the "MoveBackward" command but just add a reversed walking animation.
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 29th Jan 2020 20:20
find out what frames you want to play and put them in the #'s
(if your animation frames are going down you may need to use a negative speed - SetAnimationSpeed(e,-1) too)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 30th Jan 2020 20:23 Edited at: 30th Jan 2020 20:24
Even easier (and maybe look better too), turn the NPC 180
and have it walk forward...
MoveForward or "SetCharacterToWalk(e)" if that works for ya.
PM
fearlesswee
4
Years of Service
User Offline
Joined: 30th Aug 2019
Location: United States
Posted: 1st Feb 2020 03:34
To make him turn around and just walk sounds the easiest, but to do that I'd have to find a way to get a position that is behind him, probably using some math regarding his current XYZ coordinates and his current rotation/heading. I'm not sure how to do this in GameGuru however.
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 1st Feb 2020 09:04
local distance = 100
local angy = g_Entity[e]['angley']
local posx = math.sin(angy) * distance
local posy = g_Entity[e]['y']
local posz = math.cos(angy) * distance
AIEntityGoToPosition(g_Entity[e]['obj'],posx,posy,posz)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11
3com
9
Years of Service
User Offline
Joined: 18th May 2014
Location: Catalonia
Posted: 1st Feb 2020 09:12
@ fearlesswee
You should probably analyze the file "ai_fantasyally_imp.lua", you will find routines that could help you give a new approach to the problem.
If I have understood correctly you want to prevent the civilian from getting in front of the player, preventing him from moving forward, for example to enter an enclosure.
This involves adding to your script a routine that prevents the civilian from walking ahead of the player at all times, thus eliminating the problem in any situation that may occur throughout the game.

It will always be better than having to move the civilian back whenever necessary, perhaps by pressing a key, or raycasting the civilian against all the obstacles that can be found on the map, which would be more laborious and difficult to achieve.
Laptop: Lenovo - Intel(R) Celeron(R) CPU 1005M @ 1.90GHz

OS: Windows 10 (64) - Ram: 4 gb - Hd: 283 gb - Video card: Intel(R) HD Graphics
cpu mark: 10396.6
2d graphics mark: 947.9
3d graphics mark: 8310.9
memory mark 2584.8
Disk mark: 1146.3
Passmark rating: 3662.4

PM
GubbyBlips
5
Years of Service
User Offline
Joined: 14th Jan 2019
Location:
Posted: 1st Feb 2020 18:15
Waiting for a keypress is a good idea @ 3com

in ARK for example there are keys to call your pets to come to you,
that way any time there is a blocking issue, you could just move to a certain
spot and press a key so they move there and get out of the way!

@ small g, fearlesswee

Here's some global functions that might help-- and you can
incorporate them into smallg's dandy script!

LookAtPlayer(e)
RotateToPlayer(e)
RotateToCamera(e)
RotateToPlayerSlowly(e,v)
RotateToPlayerWithOffset(e,angleoffset)

PM
fearlesswee
4
Years of Service
User Offline
Joined: 30th Aug 2019
Location: United States
Posted: 2nd Feb 2020 00:57 Edited at: 2nd Feb 2020 01:30
Quote: "local distance = 100
local angy = g_Entity[e]['angley']
local posx = math.sin(angy) * distance
local posy = g_Entity[e]['y']
local posz = math.cos(angy) * distance
AIEntityGoToPosition(g_Entity[e]['obj'],posx,posy,posz)"


Thank you smallg, I'll go ahead and try this!

Quote: "You should probably analyze the file "ai_fantasyally_imp.lua""


Is that part of the fantasy pack DLC? I do not have it. I think smallg's solution will work though, so I don't think I'll need to do that anyways

Quote: "RotateToPlayerWithOffset(e,angleoffset)"


Oooo I feel like this one might come into handy with some stuff I plan to add later, thanks for pointing this out!

EDIT: smallg's code didn't seem to work, at first he does absolutely nothing, but after removing the "posy" (so it's an X and Z position only, as other calls to "GoToPosition" only use X and Z) he runs to a seemingly random part of the world, and it's always the same part of the world regardless of where he is before, and what direction he is facing.
smallg
Community Leader
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 5th Feb 2020 19:18
Ah yes it should probably be

local distance = 100
local angy = g_Entity[e]['angley']
local posx = math.sin(angy) * distance
local posz = math.cos(angy) * distance
AIEntityGoToPosition(g_Entity[e]['obj'],g_Entity[e]['x']+posx,g_Entity[e]['z']+posz)
lua guide for GG
https://steamcommunity.com/sharedfiles/filedetails/?id=398177770
windows 10
i5 @4ghz, 8gb ram, AMD R9 200 series , directx 11

Login to post a reply

Server time is: 2024-05-03 00:30:25
Your offset time is: 2024-05-03 00:30:25