Example #1
0
        void OnTriggerEnter(Collider collider)
        {
            if (collider.gameObject.layer == UnityLayerManager.GetLayerIndex(EUnityLayerName.VehicleTrigger))
            {
                _collidedTriggerCount++;

                var vehicle = VehicleEntityUtility.GetVehicleFromChildCollider(collider);
                if (vehicle != null)
                {
                    SetCollisionState(vehicle, EVehicleCollisionState.Enter);

                    var collisionTime = MyGameTime.time;
                    if (collisionTime - _lastCollisionTime > 0.34f)
                    {
                        var damage = CalcPlayerCollisionDamage(vehicle);
                        if (DamageEnabled && damage > 0.0f)
                        {
                            var sourcePlayer = vehicle.hasOwnerId ? AllContext.player.GetEntityWithEntityKey(vehicle.ownerId.Value) : null;
                            VehicleDamageUtility.DoPlayerDamage(AllContext, sourcePlayer, _playerEntity, damage);
                        }
                        _lastCollisionTime = collisionTime;
                    }
                }
            }
        }
Example #2
0
 void OnTriggerStay(Collider collider)
 {
     if (collider.gameObject.layer == UnityLayerManager.GetLayerIndex(EUnityLayerName.VehicleTrigger))
     {
         var vehicle = VehicleEntityUtility.GetVehicleFromChildCollider(collider);
         if (vehicle != null)
         {
             SetCollisionState(vehicle, EVehicleCollisionState.Stay);
         }
     }
 }
Example #3
0
        void OnTriggerExit(Collider collider)
        {
            if (collider.gameObject.layer == UnityLayerManager.GetLayerIndex(EUnityLayerName.VehicleTrigger))
            {
                _collidedTriggerCount--;

                if (_collidedTriggerCount <= 0)
                {
                    var vehicle = VehicleEntityUtility.GetVehicleFromChildCollider(collider);
                    if (vehicle != null)
                    {
                        SetCollisionState(vehicle, EVehicleCollisionState.None);
                    }

                    _collidedTriggerCount = 0;
                }
            }
        }