1
This commit is contained in:
@@ -18,6 +18,7 @@ namespace BITFALL
|
||||
public record InstanceBullet : SpawnBullet
|
||||
{
|
||||
public Vector3 currentPos;
|
||||
public float InitialForce;
|
||||
public float currentSpeed = 64;
|
||||
public BITBullet model;
|
||||
}
|
||||
@@ -45,7 +46,7 @@ namespace BITFALL
|
||||
public UnityPool<BITBullet> pool = new();
|
||||
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
public List<InstanceBullet> instances = new();
|
||||
private readonly List<InstanceBullet> instances = new();
|
||||
private readonly RaycastHit[] _raycastHits = new RaycastHit[16];
|
||||
private void Start()
|
||||
{
|
||||
@@ -57,7 +58,6 @@ namespace BITFALL
|
||||
}
|
||||
private void FixedUpdate()
|
||||
{
|
||||
instances ??= new List<InstanceBullet>();
|
||||
foreach (var bullet in instances.ToArray())
|
||||
{
|
||||
var size = Physics.RaycastNonAlloc(bullet.currentPos, bullet.forward, _raycastHits, bullet.currentSpeed * Time.fixedDeltaTime, layerMask);
|
||||
@@ -95,7 +95,8 @@ namespace BITFALL
|
||||
rot = x.rot,
|
||||
forward = x.forward,
|
||||
initialDamage = x.initialDamage,
|
||||
model = instance
|
||||
model = instance,
|
||||
InitialForce = x.InitialForce,
|
||||
};
|
||||
var instanceTransform = instance.transform;
|
||||
instanceTransform.SetPositionAndRotation(x.pos, x.rot);
|
||||
@@ -118,17 +119,23 @@ namespace BITFALL
|
||||
if (layerMask.Includes(raycastHit.collider.gameObject.layer) is false) return false;
|
||||
var msg = new DamageMessage()
|
||||
{
|
||||
target = damagable.Entity,
|
||||
hit = damagable,
|
||||
damage = bullet.initialDamage,
|
||||
Target = damagable.Entity,
|
||||
Hit = damagable,
|
||||
Damage = bullet.initialDamage,
|
||||
};
|
||||
damageService.Execute(msg);
|
||||
}
|
||||
|
||||
if (raycastHit.rigidbody is not null)
|
||||
var _rigidbody = (raycastHit.rigidbody,damagable?.Rigidbody) switch
|
||||
{
|
||||
if(raycastHit.rigidbody.gameObject.layer is not 0)
|
||||
raycastHit.rigidbody.AddForceAtPositionAsync(force, raycastHit.point, ForceMode.Impulse).Forget();
|
||||
(null, null) => null,
|
||||
(null, not null) => damagable?.Rigidbody,
|
||||
(not null, null) => raycastHit.rigidbody,
|
||||
(not null, not null) => raycastHit.rigidbody,
|
||||
};
|
||||
if (_rigidbody is not null && _rigidbody.gameObject.layer is not 0)
|
||||
{
|
||||
_rigidbody.AddForceAtPositionAsync(force, raycastHit.point, ForceMode.Impulse).Forget();
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user