Exemple #1
0
        public void UpdateTankEngine(FixedUpdateEvent evt, TankEngineMovableNode tank)
        {
            TankEngineComponent       tankEngine       = tank.tankEngine;
            TankEngineConfigComponent tankEngineConfig = tank.tankEngineConfig;
            TrackComponent            track            = tank.track;
            ChassisComponent          chassis          = tank.chassis;
            float effectiveMoveAxis = chassis.EffectiveMoveAxis;
            float effectiveTurnAxis = chassis.EffectiveTurnAxis;
            bool  hasCollision      = tank.tankCollision.HasCollision;

            tankEngine.CollisionTimerSec = (hasCollision == tankEngine.HasValuableCollision) ? 0f : (tankEngine.CollisionTimerSec + evt.DeltaTime);
            if (tankEngine.CollisionTimerSec >= tankEngineConfig.EngineCollisionIntervalSec)
            {
                tankEngine.HasValuableCollision = hasCollision;
            }
            if (effectiveMoveAxis != 0f)
            {
                this.UpdateTankEngine(tankEngine, tankEngineConfig, tankEngine.HasValuableCollision, track, evt.DeltaTime, effectiveMoveAxis, tank.speed.Acceleration, tank.speedConfig.ReverseAcceleration, tank.speed.Speed, tankEngine.MovingBorder);
            }
            else if (effectiveTurnAxis == 0f)
            {
                tankEngine.Value = 0f;
            }
            else
            {
                this.UpdateTankEngine(tankEngine, tankEngineConfig, tankEngine.HasValuableCollision, track, evt.DeltaTime, effectiveTurnAxis, tank.speedConfig.TurnAcceleration, tank.speedConfig.ReverseTurnAcceleration, tank.speed.TurnSpeed, tank.tankEngineConfig.EngineTurningBorder);
            }
        }
Exemple #2
0
        public void InitTankEngine(NodeAddedEvent evt, SingleNode <TankEngineConfigComponent> tank)
        {
            TankEngineComponent component = new TankEngineComponent {
                MovingBorder         = tank.component.MinEngineMovingBorder,
                Value                = 0f,
                CollisionTimerSec    = 0f,
                HasValuableCollision = false
            };

            tank.Entity.AddComponent(component);
        }
Exemple #3
0
        private void UpdateTankEngine(TankEngineComponent tankEngine, TankEngineConfigComponent tankEngineConfig, bool hasCollision, TrackComponent track, float dt, float currentAxis, float straightAcceleration, float reverseAcceleration, float maxSpeed, float border)
        {
            float b = border;

            if (((track.LeftTrack.numContacts + track.RightTrack.numContacts) > 0) && hasCollision)
            {
                b = tankEngineConfig.MaxEngineMovingBorder;
            }
            float num4 = (b * ((currentAxis <= 0f) ? reverseAcceleration : straightAcceleration)) / maxSpeed;

            tankEngine.Value += num4 * dt;
            tankEngine.Value  = Mathf.Min(tankEngine.Value, b);
        }