-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNpcMovingUtils.lua
More file actions
53 lines (48 loc) · 1.79 KB
/
NpcMovingUtils.lua
File metadata and controls
53 lines (48 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
ShitUtils = require("ShitUtils.lua")
local NpcMovingUtils = {}
---@param entity entEntity
---@param position Vector4
---@return void
function NpcMovingUtils.WalkTo(entity, position)
local activeCmdId = entity:GetAIControllerComponent():GetActiveCommandID("AIMoveToCommand")
if activeCmdId ~= 0 then
return
end
local positionSpec = ShitUtils.ToPositionSpec(position)
local cmd = AIMoveToCommand.new({
movementTarget = positionSpec,
rotateEntityTowardsFacingTarget = false,
ignoreNavigation = true,
desiredDistanceFromTarget = 1.0,
movementType = moveMovementType.Sprint,
finishWhenDestinationReached = true,
useStop = false,
useStart = false
})
local aiControllerComponent = entity:GetAIControllerComponent();
aiControllerComponent:SendCommand(cmd)
end
---@param entity entEntity
---@param position Vector4
---@return void
function NpcMovingUtils.TeleportTo(entity, position)
local activeCmdId = entity:GetAIControllerComponent():GetActiveCommandID("AITeleportCommand")
if activeCmdId ~= 0 then
entity:GetAIControllerComponent():CancelCommandById(activeCmdId)
end
local cmd = AITeleportCommand.new({doNavTest = false, rotation = 1, position = position})
entity:GetAIControllerComponent():SendCommand(cmd)
end
---@param entity entEntity
---@param rotation EulerAngles
---@return void
function NpcMovingUtils.Rotate(entity, rotation)
local activeCmdId = entity:GetAIControllerComponent():GetActiveCommandID("AIRotateToCommand")
if (activeCmdId) ~= 0 then
return
end
local targetPosition = ShitUtils.EulerAngleToPosition(entity:GetWorldPosition(), rotation)
local cmd = AIRotateToCommand.new({target = ShitUtils.ToPositionSpec(targetPosition), angleTolerance = 5.0, angleOffset = 0.0, speed = 1.0})
entity:GetAIControllerComponent():SendCommand(cmd)
end
return NpcMovingUtils