Esempio n. 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);
            }
        }
Esempio n. 2
0
        private float RecalculateRelativeTurnSpeed(ChassisNode node, float dt, float maxTurnSpeed, float relativeTurnSpeed, float slopeCoeff)
        {
            ChassisComponent       chassis       = node.chassis;
            ChassisConfigComponent chassisConfig = node.chassisConfig;
            float num  = node.speedConfig.TurnAcceleration * 0.01745329f;
            float num2 = this.CalculateTurnCoefficient(node.track);
            float num3 = 0f;

            if (chassis.EffectiveTurnAxis == 0f)
            {
                num3 = ((-MathUtil.Sign(relativeTurnSpeed) * num) * slopeCoeff) * dt;
                if (MathUtil.Sign(relativeTurnSpeed) != MathUtil.Sign(relativeTurnSpeed + num3))
                {
                    num3 = -relativeTurnSpeed;
                }
            }
            else
            {
                if (this.IsReversedTurn(chassis.EffectiveTurnAxis, relativeTurnSpeed))
                {
                    num = node.speedConfig.ReverseTurnAcceleration * 0.01745329f;
                }
                num3 = ((chassis.EffectiveTurnAxis * num) * slopeCoeff) * dt;
                if ((chassis.EffectiveMoveAxis == -1f) && chassisConfig.ReverseBackTurn)
                {
                    num3 = -num3;
                }
            }
            return(Mathf.Clamp((float)(relativeTurnSpeed + num3), (float)(-maxTurnSpeed * num2), (float)(maxTurnSpeed * num2)));
        }
Esempio n. 3
0
        private void UpdateInput(ChassisNode tank, bool inputEnabled)
        {
            ChassisComponent chassis = tank.chassis;
            bool             flag    = tank.Entity.HasComponent <TankMovableComponent>();

            chassis.EffectiveMoveAxis = !flag ? 0f : chassis.MoveAxis;
            chassis.EffectiveTurnAxis = !flag ? 0f : chassis.TurnAxis;
        }
        private void CheckChassisChange(AutopilotTankNode tank)
        {
            ChassisComponent chassis = tank.chassis;

            if ((chassis.MoveAxis != tank.navigationData.LastMove) || (chassis.TurnAxis != tank.navigationData.LastTurn))
            {
                base.ScheduleEvent <ChassisControlChangedEvent>(tank);
                tank.navigationData.LastMove = chassis.MoveAxis;
                tank.navigationData.LastTurn = chassis.TurnAxis;
            }
        }
Esempio n. 5
0
 public SuspensionRay(Rigidbody body, Vector3 origin, Vector3 direction, ChassisConfigComponent chassisConfig, ChassisComponent chassis, float damping)
 {
     this.rigidbody     = body;
     this.origin        = origin;
     this.direction     = direction;
     this.chassisConfig = chassisConfig;
     this.chassis       = chassis;
     this.damping       = damping;
     this.ConvertToGlobal();
     this.rayHit.distance = chassisConfig.MaxRayLength;
     this.rayHit.point    = this.globalOrigin + (this.globalDirection * chassisConfig.MaxRayLength);
 }
Esempio n. 6
0
        public void InitTankChassis(NodeAddedEvent evt, ChassisInitNode node)
        {
            ChassisComponent chassis = new ChassisComponent();

            this.CreateTracks(node, chassis);
            node.Entity.AddComponent(chassis);
            node.Entity.AddComponent <EffectiveSpeedComponent>();
            ChassisSmootherComponent component = new ChassisSmootherComponent();

            component.maxSpeedSmoother.Reset(node.speed.Speed);
            component.maxTurnSpeedSmoother.Reset(node.speed.TurnSpeed);
            node.Entity.AddComponent(component);
            node.rigidbody.Rigidbody.mass = node.weight.Weight;
        }
Esempio n. 7
0
        private DiscreteTankControl GetControl(TankNode tankNode, WeaponNode weaponNode)
        {
            DiscreteTankControl control  = new DiscreteTankControl();
            ChassisComponent    chassis  = tankNode.chassis;
            MoveControl         control2 = new MoveControl {
                MoveAxis = chassis.EffectiveMoveAxis,
                TurnAxis = chassis.EffectiveTurnAxis
            };

            control.TurnAxis      = Mathf.RoundToInt(control2.TurnAxis);
            control.MoveAxis      = Mathf.RoundToInt(control2.MoveAxis);
            control.WeaponControl = Mathf.RoundToInt(weaponNode.weaponRotationControl.EffectiveControl);
            return(control);
        }
Esempio n. 8
0
        private float CalculateForcePerRay(ChassisNode node, float dt, float forwardRelativeSpeed)
        {
            ChassisConfigComponent chassisConfig = node.chassisConfig;
            ChassisComponent       chassis       = node.chassis;
            float          maxSpeed     = node.effectiveSpeed.MaxSpeed;
            TrackComponent track        = node.track;
            Rigidbody      rigidbody    = node.rigidbody.Rigidbody;
            float          acceleration = node.speed.Acceleration;
            float          num3         = 0f;

            if (chassis.EffectiveMoveAxis == 0f)
            {
                num3 = (-MathUtil.Sign(forwardRelativeSpeed) * acceleration) * dt;
                if (MathUtil.Sign(forwardRelativeSpeed) != MathUtil.Sign(forwardRelativeSpeed + num3))
                {
                    num3 = -forwardRelativeSpeed;
                }
            }
            else
            {
                if (this.IsReversedMove(chassis.EffectiveMoveAxis, forwardRelativeSpeed))
                {
                    acceleration = node.speedConfig.ReverseAcceleration;
                }
                num3 = (chassis.EffectiveMoveAxis * acceleration) * dt;
            }
            float f    = Mathf.Clamp(forwardRelativeSpeed + num3, -maxSpeed, maxSpeed);
            float num5 = f - forwardRelativeSpeed;
            float num6 = 1f;
            float num7 = (maxSpeed <= 0f) ? num6 : Mathf.Clamp01(1f - Mathf.Abs((float)(forwardRelativeSpeed / maxSpeed)));

            if ((num7 < num6) && ((chassis.EffectiveMoveAxis * MathUtil.Sign(forwardRelativeSpeed)) > 0f))
            {
                num5 *= num7 / num6;
            }
            float num8 = num5 / dt;

            if ((Mathf.Abs(num8) < 4f) && (Mathf.Abs(f) > (0.5f * maxSpeed)))
            {
                num8 = MathUtil.SignEpsilon(num8, 0.1f) * 4f;
            }
            int   num10 = track.LeftTrack.numContacts + track.RightTrack.numContacts;
            int   num11 = 2 * chassisConfig.NumRaysPerTrack;
            float num12 = ((num8 * rigidbody.mass) * (num10 + (0.42f * (num11 - track.LeftTrack.numContacts)))) / ((float)num11);

            return((num10 <= 0) ? num12 : (num12 / ((float)num10)));
        }
        private void CalculateRotation(AutopilotTankNode tank)
        {
            Vector3          movePosition = tank.navigationData.MovePosition;
            ChassisComponent chassis      = tank.chassis;

            chassis.TurnAxis = 0f;
            Vector3 vector2 = tank.rigidbody.Rigidbody.transform.InverseTransformPoint(movePosition);

            if (vector2.x > 0.2)
            {
                chassis.TurnAxis = 1f;
            }
            if (vector2.x < -0.2)
            {
                chassis.TurnAxis = -1f;
            }
        }
Esempio n. 10
0
        private void CreateTracks(ChassisInitNode node, ChassisComponent chassis)
        {
            Entity entity = node.Entity;
            ChassisConfigComponent chassisConfig = node.chassisConfig;
            Rigidbody      rigidbody             = node.rigidbody.Rigidbody;
            BoxCollider    boundsCollider        = node.tankColliders.BoundsCollider;
            float          trackLength           = boundsCollider.size.z * 0.8f;
            float          num2                = boundsCollider.size.x - chassisConfig.TrackSeparation;
            Vector3        vector3             = boundsCollider.center - new Vector3(0f, boundsCollider.size.y / 2f, 0f);
            Vector3        trackCenterPosition = vector3 + new Vector3(-0.5f * num2, chassisConfig.NominalRayLength, 0f);
            Vector3        vector6             = vector3 + new Vector3(0.5f * num2, chassisConfig.NominalRayLength, 0f);
            float          damping             = node.damping.Damping;
            TrackComponent component           = new TrackComponent {
                LeftTrack  = new Track(rigidbody, chassisConfig.NumRaysPerTrack, trackCenterPosition, trackLength, chassisConfig, chassis, -1, damping),
                RightTrack = new Track(rigidbody, chassisConfig.NumRaysPerTrack, vector6, trackLength, chassisConfig, chassis, 1, damping)
            };
            int layerMask = LayerMasks.VISIBLE_FOR_CHASSIS_SEMI_ACTIVE;

            component.LeftTrack.SetRayсastLayerMask(layerMask);
            component.RightTrack.SetRayсastLayerMask(layerMask);
            entity.AddComponent(component);
        }
Esempio n. 11
0
        private void UpdateSelfInput(ChassisNode tank, bool inputEnabled, bool inverse)
        {
            ChassisComponent chassis = tank.chassis;
            float            x       = !inputEnabled ? 0f : (InputManager.GetUnityAxis(RIGHT_AXIS) - InputManager.GetUnityAxis(LEFT_AXIS));
            float            y       = !inputEnabled ? 0f : (InputManager.GetUnityAxis(FORWARD_AXIS) - InputManager.GetUnityAxis(BACKWARD_AXIS));

            if (inverse && (y < 0f))
            {
                x *= -1f;
            }
            Vector2 vector  = new Vector2(chassis.TurnAxis, chassis.MoveAxis);
            Vector2 vector2 = new Vector2(x, y);

            if (vector2 != vector)
            {
                chassis.TurnAxis = x;
                chassis.MoveAxis = y;
                bool flag = tank.Entity.HasComponent <TankMovableComponent>();
                chassis.EffectiveMoveAxis = !flag ? 0f : chassis.MoveAxis;
                chassis.EffectiveTurnAxis = !flag ? 0f : chassis.TurnAxis;
                base.ScheduleEvent <ChassisControlChangedEvent>(tank);
            }
        }
 private void ApplyMoveControl(ChassisComponent chassis, float moveAxis, float turnAxis)
 {
     base.Log.Debug("APPLY MOVE_CONTROL");
     chassis.MoveAxis = moveAxis;
     chassis.TurnAxis = turnAxis;
 }
Esempio n. 13
0
        private void AdjustSuspensionSpringCoeff(ChassisConfigComponent chassisConfig, ChassisComponent chassis, Rigidbody rigidbody)
        {
            float num = Physics.gravity.magnitude * rigidbody.mass;

            chassis.SpringCoeff = num / ((2 * chassisConfig.NumRaysPerTrack) * (chassisConfig.MaxRayLength - chassisConfig.NominalRayLength));
        }
Esempio n. 14
0
        private void CreateSuspensionRays(Rigidbody rigidbody, int numRays, Vector3 trackCenterPosition, float trackLength, ChassisConfigComponent chassisConfig, ChassisComponent chassis, float damping)
        {
            this.rays = new SuspensionRay[numRays];
            float num = trackLength / ((float)(this.rays.Length - 1));

            for (int i = 0; i < numRays; i++)
            {
                Vector3 origin = new Vector3(trackCenterPosition.x, trackCenterPosition.y, (trackCenterPosition.z + (0.5f * trackLength)) - (i * num));
                this.rays[i] = new SuspensionRay(rigidbody, origin, Vector3.down, chassisConfig, chassis, damping);
            }
        }
Esempio n. 15
0
 public Track(Rigidbody rigidbody, int numRays, Vector3 trackCenterPosition, float trackLength, ChassisConfigComponent chassisConfig, ChassisComponent chassis, int side, float damping)
 {
     this.side = side;
     this.CreateSuspensionRays(rigidbody, numRays, trackCenterPosition, trackLength, chassisConfig, chassis, damping);
 }