change distance of enemy ped

This commit is contained in:
in0finite 2021-09-13 00:12:41 +02:00
parent 217bf12473
commit 71fc261100
4 changed files with 12 additions and 9 deletions

View file

@ -52,9 +52,9 @@ namespace SanAndreasUnity.Behaviours
return ped.gameObject.GetOrAddComponent<PedAI>();
}
public static PedAI SpawnPedAI(int pedId, Transform nearbyTransform)
public static PedAI SpawnPedAI(int pedId, Transform nearbyTransform, float minDistance = 5f, float maxDistance = 15f)
{
if (GetPositionForPedSpawn (out var pos, out var rot, nearbyTransform))
if (GetPositionForPedSpawn (out var pos, out var rot, nearbyTransform, minDistance, maxDistance))
return SpawnPedAI(pedId, pos, rot);
return null;
}
@ -78,7 +78,12 @@ namespace SanAndreasUnity.Behaviours
return null;
}
public static bool GetPositionForPedSpawn (out Vector3 pos, out Quaternion rot, Transform nearbyTransform)
public static bool GetPositionForPedSpawn(
out Vector3 pos,
out Quaternion rot,
Transform nearbyTransform,
float minDistance = 5f,
float maxDistance = 15f)
{
pos = Vector3.zero;
rot = Quaternion.identity;
@ -88,7 +93,7 @@ namespace SanAndreasUnity.Behaviours
Vector3 offset = Random.onUnitSphere;
offset.y = 0f;
offset.Normalize ();
offset *= Random.Range (5f, 15f);
offset *= Random.Range (minDistance, maxDistance);
pos = nearbyTransform.TransformPoint (offset);
rot = Random.rotation;

View file

@ -131,7 +131,7 @@ namespace SanAndreasUnity.Commands
if (!GetPedModelId(arguments, 1, out int modelId))
return pedModelIdDoesNotExist;
var pedAI = Ped.SpawnPedAI(modelId, player.OwnedPed.transform);
var pedAI = Ped.SpawnPedAI(modelId, player.OwnedPed.transform, 15f, 30f);
// add weapon ...
pedAI.StartChasing(player.OwnedPed);

View file

@ -140,8 +140,7 @@ namespace SanAndreasUnity.UI {
GUI.enabled = NetUtils.IsServer;
if (GUI.Button(itemRect, "Spawn"))
{
if (Ped.GetPositionForPedSpawn(out Vector3 pos, out Quaternion rot, Ped.Instance.transform))
Ped.SpawnPedAI(def.Id, pos, rot);
Ped.SpawnPedAI(def.Id, Ped.Instance.transform);
}
GUI.enabled = true;

View file

@ -70,8 +70,7 @@ namespace SanAndreasUnity.UI {
{
for (int i = 0; i < 5; i++)
{
if (Ped.GetPositionForPedSpawn(out Vector3 pos, out Quaternion rot, nearbyTransform))
Ped.SpawnPedAI(Ped.RandomPedId, pos, rot);
Ped.SpawnPedAI(Ped.RandomPedId, nearbyTransform);
}
}