Esempio n. 1
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. 2
0
 public void FixedUpdate(FixedUpdateEvent evt, ChassisNode chassisNode, [JoinSelf] Optional <SingleNode <TankSyncComponent> > tankSync, [JoinByTank] Optional <SingleNode <TankJumpComponent> > tankJump, [JoinAll] SingleNode <GameTankSettingsComponent> gameTankSettings, [JoinAll] Optional <SingleNode <BattleActionsStateComponent> > inputState)
 {
     if (!tankJump.IsPresent() || !tankJump.Get().component.isNearBegin())
     {
         bool inputEnabled = inputState.IsPresent();
         if (chassisNode.Entity.HasComponent <SelfTankComponent>())
         {
             this.UpdateSelfInput(chassisNode, inputEnabled, gameTankSettings.component.MovementControlsInverted);
         }
         this.UpdateInput(chassisNode, inputEnabled);
         ChassisSmootherComponent chassisSmoother = chassisNode.chassisSmoother;
         chassisSmoother.maxSpeedSmoother.SetTargetValue(chassisNode.speed.Speed);
         float num = chassisSmoother.maxSpeedSmoother.Update(evt.DeltaTime);
         chassisNode.effectiveSpeed.MaxSpeed = num;
         Rigidbody rigidbody = chassisNode.rigidbody.Rigidbody;
         if (rigidbody)
         {
             float x = rigidbody.velocity.x;
             float z = rigidbody.velocity.z;
             float t = (!tankJump.IsPresent() || !tankJump.Get().component.OnFly) ? 1f : tankJump.Get().component.GetSlowdownLerp();
             if (((x * x) + (z * z)) > (num * num))
             {
                 float   num5     = Mathf.Lerp(1f, num / ((float)Math.Sqrt((double)((x * x) + (z * z)))), t);
                 Vector3 velocity = new Vector3(rigidbody.velocity.x * num5, rigidbody.velocity.y, rigidbody.velocity.z * num5);
                 rigidbody.SetVelocitySafe(velocity);
             }
             chassisSmoother.maxTurnSpeedSmoother.SetTargetValue(chassisNode.speed.TurnSpeed);
             chassisNode.effectiveSpeed.MaxTurnSpeed = chassisSmoother.maxTurnSpeedSmoother.Update(evt.DeltaTime);
             this.AdjustSuspensionSpringCoeff(chassisNode.chassisConfig, chassisNode.chassis, chassisNode.rigidbody.Rigidbody);
             float updatePeriod = 0f;
             if (!tankSync.IsPresent())
             {
                 updatePeriod  = chassisNode.cameraVisibleTrigger.IsVisible ? 0.05f : 0.1f;
                 updatePeriod += Random.value * 0.05f;
             }
             if (this.UpdateSuspensionContacts(chassisNode.track, evt.DeltaTime, updatePeriod) && tankJump.IsPresent())
             {
                 tankJump.Get().component.FinishAndSlowdown();
             }
             this.ApplyMovementForces(chassisNode, evt.DeltaTime);
             this.ApplyStaticFriction(chassisNode.track, chassisNode.rigidbody.Rigidbody);
         }
     }
 }