mirror of
https://github.com/GTA-ASM/SanAndreasUnity
synced 2024-11-21 19:43:03 +00:00
peds can not damage other peds in the same vehicle
This commit is contained in:
parent
21644998cb
commit
d37d601082
2 changed files with 47 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
|||
using UnityEngine;
|
||||
using SanAndreasUnity.Behaviours.Vehicles;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SanAndreasUnity.Behaviours.Peds.States
|
||||
{
|
||||
|
@ -11,15 +12,39 @@ namespace SanAndreasUnity.Behaviours.Peds.States
|
|||
// - add real aim anims ?
|
||||
// - drive-by exiting state - activated when going from drive-by to sitting state, or when trying to exit vehicle
|
||||
// - weapon's gun flash should depend on last time when fired, not on anim time - maybe don't change it, because we may play real aim anims
|
||||
|
||||
|
||||
|
||||
|
||||
readonly List<GameObject> m_gameObjectToIgnoreWhenRaycasting = new List<GameObject>();
|
||||
readonly List<int> m_layersToIgnoreWhenRaycasting = new List<int>();
|
||||
|
||||
public WeaponAttackParams WeaponAttackParams
|
||||
{
|
||||
get => new WeaponAttackParams
|
||||
get
|
||||
{
|
||||
GameObjectToIgnoreWhenRaycasting = this.CurrentVehicle != null ? this.CurrentVehicle.gameObject : null,
|
||||
};
|
||||
m_gameObjectToIgnoreWhenRaycasting.Clear();
|
||||
m_layersToIgnoreWhenRaycasting.Clear();
|
||||
|
||||
if (this.CurrentVehicle != null)
|
||||
{
|
||||
m_gameObjectToIgnoreWhenRaycasting.Add(this.CurrentVehicle.gameObject);
|
||||
m_layersToIgnoreWhenRaycasting.Add(LayerMask.NameToLayer(Ped.PedBoneLayerName));
|
||||
|
||||
if (this.CurrentVehicle.HighDetailMeshesParent != null)
|
||||
{
|
||||
m_gameObjectToIgnoreWhenRaycasting.Add(this.CurrentVehicle.HighDetailMeshesParent.gameObject);
|
||||
m_layersToIgnoreWhenRaycasting.Add(Vehicle.MeshLayer);
|
||||
}
|
||||
|
||||
return new WeaponAttackParams
|
||||
{
|
||||
GameObjectsToIgnoreWhenRaycasting = m_gameObjectToIgnoreWhenRaycasting,
|
||||
LayersToIgnoreWhenRaycasting = m_layersToIgnoreWhenRaycasting,
|
||||
};
|
||||
}
|
||||
|
||||
return WeaponAttackParams.Default;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -75,7 +75,8 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
public struct WeaponAttackParams
|
||||
{
|
||||
public GameObject GameObjectToIgnoreWhenRaycasting { get; set; }
|
||||
public List<int> LayersToIgnoreWhenRaycasting { get; set; }
|
||||
public List<GameObject> GameObjectsToIgnoreWhenRaycasting { get; set; }
|
||||
|
||||
public static WeaponAttackParams Default { get => new WeaponAttackParams(); }
|
||||
}
|
||||
|
@ -653,7 +654,7 @@ namespace SanAndreasUnity.Behaviours
|
|||
m_lastRaycastWeaponAttackParams = parameters;
|
||||
|
||||
|
||||
if (null == parameters.GameObjectToIgnoreWhenRaycasting)
|
||||
if (null == parameters.GameObjectsToIgnoreWhenRaycasting)
|
||||
return Physics.Raycast(source, dir, out hit, this.MaxRange, WeaponsManager.Instance.projectileRaycastMask);
|
||||
|
||||
|
||||
|
@ -670,7 +671,7 @@ namespace SanAndreasUnity.Behaviours
|
|||
|
||||
var validHits = s_raycastHitBuffer
|
||||
.Take(numHits)
|
||||
.Where(h => h.collider != null && parameters.GameObjectToIgnoreWhenRaycasting != h.transform.gameObject && !parameters.GameObjectToIgnoreWhenRaycasting.transform.IsParentOf(h.transform));
|
||||
.Where(h => h.collider != null && !ShouldIgnoreObjectWhenRaycasting(h.collider, parameters));
|
||||
|
||||
if (!validHits.Any())
|
||||
{
|
||||
|
@ -683,6 +684,20 @@ namespace SanAndreasUnity.Behaviours
|
|||
return true;
|
||||
}
|
||||
|
||||
private static bool ShouldIgnoreObjectWhenRaycasting(Collider collider, WeaponAttackParams parameters)
|
||||
{
|
||||
if (!parameters.LayersToIgnoreWhenRaycasting.Contains(collider.gameObject.layer))
|
||||
return false;
|
||||
|
||||
if (parameters.GameObjectsToIgnoreWhenRaycasting.Exists(go => go == collider.gameObject))
|
||||
return true;
|
||||
|
||||
if (parameters.GameObjectsToIgnoreWhenRaycasting.Exists(go => go.transform.IsParentOf(collider.transform)))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void GetLineFromGun (out Vector3 start, out Vector3 end, WeaponAttackParams parameters)
|
||||
{
|
||||
float distance = this.MaxRange;
|
||||
|
|
Loading…
Reference in a new issue