コード例 #1
0
    /// <summary>
    /// Returns an axis value.
    /// </summary>
    /// <param name="name">Name of the axis we want to return</param>
    /// <returns></returns>
    public float GetAxis(string name)
    {
        float     tmp   = 0;
        AxisInput _axis = new AxisInput();

        if (!PauseMenuControl.Paused)
        {
            //Like with button inputs, we will first cycle through our available axis inputs.
            for (int a = 0; a < axisInputs.Length; a++)
            {
                if (axisInputs[a].Name == name)
                {
                    _axis = axisInputs[a];
                }
            }
            float TargetInput = _axis.Value;
            ///For keyboard input axes, we set a target value and add or subtract it depending on if positive/negative inputs are held or released.
            if (Input.GetKeyDown(_axis.Positive) || Input.GetKeyUp(_axis.Negative))
            {
                _axis.TargetValue += 1;
            }
            if (Input.GetKeyUp(_axis.Positive) || Input.GetKeyDown(_axis.Negative))
            {
                _axis.TargetValue -= 1;
            }
            if (!Input.GetKey(_axis.Positive) && !Input.GetKey(_axis.Negative))
            {
                _axis.TargetValue = 0;
            }
            tmp = _axis.Value + Input.GetAxisRaw(_axis.GamepadAxis);
            tmp = HedgeMath.ClampFloat(tmp, -1, 1);
        }

        return(tmp);
    }
コード例 #2
0
    /// <summary>
    /// Returns an axis value;
    /// </summary>
    /// <param name="Index">Array index of the axis we want to return</param>
    /// <returns></returns>
    public float GetAxis(int Index)
    {
        float     tmp   = 0;
        AxisInput _axis = axisInputs[Index];

        if (!PauseMenuControl.Paused)
        {
            float TargetInput = _axis.Value;
            ///For keyboard input axes, we set a target value and add or subtract it depending on if positive/negative inputs are held or released.
            if (Input.GetKeyDown(_axis.Positive) || Input.GetKeyUp(_axis.Negative))
            {
                _axis.TargetValue += 1;
            }
            if (Input.GetKeyUp(_axis.Positive) || Input.GetKeyDown(_axis.Negative))
            {
                _axis.TargetValue -= 1;
            }
            if (!Input.GetKey(_axis.Positive) && !Input.GetKey(_axis.Negative))
            {
                _axis.TargetValue = 0;
            }
            tmp = _axis.Value + Input.GetAxisRaw(_axis.GamepadAxis);
            tmp = HedgeMath.ClampFloat(tmp, -1, 1);
        }

        return(tmp);
    }
コード例 #3
0
    void Update()
    {
        if (!Player || !DebugText)
        {
            return;                        //This script will not update if there is no Player or Text assigned.
        }
        //Now that we're sure we have the necessary components, we debug Sonic's current state using its type.
        string StateDebug = "Current State: " + PlayerActions.currentState.GetType().ToString();

        //Next we split Sonic's velocity to planar and vertical so we can debug our ground speed and air speed.
        HedgeMath.SplitPlanarVector(Player.rigidBody.velocity, Player.GroundNormal, out Vector3 GroundSpeed, out Vector3 AirSpeed);
        string GroundDebug = "Ground Speed: " + GroundSpeed.magnitude.ToString("F2") + "m/s";
        string AirDebug    = "Air Speed: " + AirSpeed.magnitude.ToString("F2") + "m/s";

        //Set the debug text
        DebugText.text = StateDebug + "\n" + GroundDebug + "\n" + AirDebug;
    }
コード例 #4
0
    // Update is called once per frame
    void Update()
    {
        //Here we'll be setting all the main animator values.
        HedgeMath.SplitPlanarVector(player.rigidBody.velocity, player.GroundNormal, out Vector3 Ground, out Vector3 Air);
        Vector3 LocalAirVelocity = transform.InverseTransformDirection(Air);

        animator.SetInteger("State", Actions.StateIndex);
        animator.SetBool("Grounded", player.Grounded);
        animator.SetFloat("AirSpeed", LocalAirVelocity.y);
        animator.SetBool("Crouching", player.Crouching);
        animator.SetBool("Braking", player.Skidding);
        animator.SetBool("Dead", PlayerHealth.IsDead);
        SpinBall.GetComponent <Animator>().SetFloat("Speed", Ground.magnitude);

        SpinBall.SetActive(PlayerActions.currentState is ActionJump);

        if (PlayerActions.currentState is ActionSpindash)
        {
            animator.SetFloat("GroundSpeed", Actions.spinDashState.SpinDashCharge);
            if (!SpinDashParticles.isPlaying)
            {
                SpinDashParticles.Play();
            }
        }
        else
        {
            animator.SetFloat("GroundSpeed", Ground.magnitude);
            if (SpinDashParticles.isPlaying)
            {
                SpinDashParticles.Stop();
            }
        }

        //Set turn amount
        ///To get the turn amount, we first get which direction Sonic is turning by using a dot product between Sonic's right vector and Sonic's velocity.
        ///If the dot is positive, he is turning right. If it is negative, he is turning left.
        ///Once we have the turning amount, we set the actual Turn float. If the rotation amount is above the dead zone, we lerp Turning to the turn amount.
        ///If it is under the dead zone, we lerp it to 0.
        DeltaRotation = Vector3.Dot(transform.right, player.rigidBody.velocity.normalized) * 10;
        DeltaRotation = HedgeMath.ClampFloat(DeltaRotation, -1, 1);
        if (DeltaRotation > RotationDeadZone || DeltaRotation < -RotationDeadZone)
        {
            Turning = Mathf.Lerp(Turning, DeltaRotation, Time.deltaTime * TurnSmoothing);
        }
        else
        {
            Turning = Mathf.Lerp(Turning, 0f, Time.deltaTime * TurnSmoothing);
        }
        animator.SetFloat("HorizontalInput", Turning);

        ///Here we're simply playing and stopping the speed line particles depending on whether or not Sonic is up to speed
        ///and whether or not the particles are already playing.
        if (player.rigidBody.velocity.magnitude >= ParticleStartSpeed && !SpeedParticles.isPlaying)
        {
            SpeedParticles.Play();
        }
        else if (player.rigidBody.velocity.magnitude < ParticleStartSpeed && SpeedParticles.isPlaying)
        {
            SpeedParticles.Stop();
        }
    }
コード例 #5
0
 public void UpdateAxisValue()
 {
     Value = Mathf.SmoothDamp(Value, TargetValue, ref Velocity, Damping);
     Value = HedgeMath.ClampFloat(Value, -1, 1);
 }