Esempio n. 1
0
    public override void _IntegrateForces(Physics2DDirectBodyState bodyState)
    {
        Vector2 linearVelocity = bodyState.LinearVelocity;
        float   step           = bodyState.Step;

        PlayerInputInteraction playerInputInteraction = ListenToPlayerInput();

        linearVelocity.x -= this.floorHVelocity;
        floorHVelocity    = 0.0f;

        FloorContact floorContact = FindFloorContact(bodyState);

        ProcessSpawn(playerInputInteraction);
        ProcessShooting(playerInputInteraction, step);
        ProcessFloorContact(floorContact, step);
        linearVelocity = ProcessJump(playerInputInteraction, linearVelocity, step);
        linearVelocity = ProcessPlayerMovement(playerInputInteraction, linearVelocity, step);

        this.shooting = playerInputInteraction.Shoot;
        if (floorContact.FoundFloor)
        {
            floorHVelocity    = bodyState.GetContactColliderVelocityAtPosition(floorContact.FloorIndex).x;
            linearVelocity.x += floorHVelocity;
        }

        linearVelocity          += bodyState.TotalGravity * step;
        bodyState.LinearVelocity = linearVelocity;
    }
Esempio n. 2
0
    public override void _IntegrateForces(Physics2DDirectBodyState state)
    {
        AppliedForce  = state.TotalGravity;
        AppliedTorque = 0f;

        if (ThrusterControls.IsUFODriveEnabled)
        {
            var clampedVelocity = ThrusterControls.UFODriveVelocity.Normalized() * Mathf.Min(ThrusterControls.UFODriveVelocity.Length(), ufoDriveMaxSpeed);
            state.LinearVelocity = clampedVelocity;
            //state.LinearVelocity = ThrusterControls.UFODriveVelocity;
            state.AngularVelocity = ThrusterControls.UFODriveAngularVelocity;
        }
        else
        {
            AddForce(mainThruster.GlobalPosition - GlobalPosition, mainThruster.GetResultantThrustVector());
            AddForce(portRetroThruster.GlobalPosition - GlobalPosition, portRetroThruster.GetResultantThrustVector());
            AddForce(starboardRetroThruster.GlobalPosition - GlobalPosition, starboardRetroThruster.GetResultantThrustVector());
            AddForce(portForeThruster.GlobalPosition - GlobalPosition, portForeThruster.GetResultantThrustVector());
            AddForce(portAftThruster.GlobalPosition - GlobalPosition, portAftThruster.GetResultantThrustVector());
            AddForce(starboardForeThruster.GlobalPosition - GlobalPosition, starboardForeThruster.GetResultantThrustVector());
            AddForce(starboardAftThruster.GlobalPosition - GlobalPosition, starboardAftThruster.GetResultantThrustVector());
        }

        //Enable/Disable the UFO Drive visuals depending on chosen PropulsionMode
        //ufoDriveParticles.SetEmitting(PropulsionMode == ShipPropulsionMode.ManualUFODrive);
        ufoDriveParticles.SetEmitting(ThrusterControls.IsUFODriveEnabled);

        if (Input.IsActionJustPressed("MovementStop"))
        {
            state.LinearVelocity  = Vector2.Zero;
            state.AngularVelocity = 0f;
        }

        int contactCount = state.GetContactCount();

        if (contactCount > 0)
        {
            //GD.Print("Contact count: " + contactCount);
            for (int i = 0; i < contactCount; i++)
            {
                var vector = state.GetContactColliderVelocityAtPosition(i);
                //GD.Print("Vector: " + vector);
            }
        }
    }