Exemplo n.º 1
0
    private void Jump()
    {
        if (jumpRequested && isGrounded)
        {
            Jumped?.Invoke(moonJumpGround);
            groundCheckDistance = 0.0f;
            StartCoroutine(ResetGroundProbe());
            isGrounded = false;

            var jumpForce = moonJumpGround ? moonJumpVelocity : jumpVelocity;

            velocity  += contactNormal * jumpForce;
            velocity.y = Mathfs.Clamp(velocity.y, 0.0f, jumpForce);
        }
        jumpRequested = false;
    }
Exemplo n.º 2
0
    private void DrawResizeHandle()
    {
        var transform = platform.transform;
        var position  = transform.position;

        // @NOTE THE SCALING SHENNANIGANS ON THIS MATRIX HERE.
        Matrix4x4 matrix = Matrix4x4.TRS(position, transform.rotation, transform.localScale * 0.5f);

        // Unity's implementation of Slider2D is janky as all hell. If you don't scale the matrix, you end up either
        // passing size*0.5f into Slider2d(handlePos) resulting in weird popping behaviour when you first press the
        // mouse, or you pass in Size and have the handle be placed miles away from the corner.
        using (new Handles.DrawingScope(Color.red, matrix))
        {
            EditorGUI.BeginChangeCheck();

            var style = new GUIStyle();
            style.fontStyle        = FontStyle.Bold;
            style.fontSize         = 12;
            style.alignment        = TextAnchor.LowerCenter;
            style.normal.textColor = Color.white;

            var flatColliderSize = new Vector3(collider.size.x, 0.0f, collider.size.z);

            var handleSize = HandleUtility.GetHandleSize(Vector3.zero) * 0.35f;

            Handles.Label(collider.size + (Vector3.up * handleSize), "Resize..", style);

            Vector3 DraggedHandle = Handles.Slider2D(flatColliderSize,
                                                     transform.up, transform.right, transform.forward,
                                                     handleSize, Handles.CubeHandleCap, 0.1f);

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(platform, "Resized moving platform");
                var newSize = new Vector3(
                    Mathfs.Clamp(DraggedHandle.x, 0, Single.PositiveInfinity),
                    platform.platformHeight,
                    Mathfs.Clamp(DraggedHandle.z, 0, Single.PositiveInfinity));

                platform.platformVisual.transform.localScale = newSize;
                platform.platformSize = new Vector2(newSize.x, newSize.z);
                collider.size         = newSize;
            }
        }
    }
Exemplo n.º 3
0
    private void Update()
    {
        // Don't play wheel sounds when not grounded, or busy playing the jump sound.
        var actualSpeed = rBody.velocity.magnitude;

        var clampedSpeed = Mathfs.Clamp(actualSpeed, minSpeed, maxSpeed);
        var t            = Mathfs.InverseLerp(minSpeed, maxSpeed, clampedSpeed);

        if (!isPlayingJumpSound)
        {
            var volume = Mathfs.Lerp(minVolume, maxVolume, Mathfs.Smooth01(t));
            audioSource.volume = Mathfs.SmoothDamp(audioSource.volume, volume, ref dVolume, 1.0f);
        }
        else if (!playerMovement.IsGrounded())
        {
            audioSource.volume = Mathfs.SmoothDamp(audioSource.volume, airWheelVolume, ref dVolume, 0.1f);
        }

        var pitch = Mathfs.Lerp(minPitch, maxPitch, Mathfs.Smooth01(t));

        audioSource.pitch = Mathfs.SmoothDamp(audioSource.pitch, pitch, ref dPitch, dPitch < 0.0f ? 0.2f : 1.0f);
    }
 public static float Clamp(this float v, float min, float max) =>
 Mathfs.Clamp(v, min, max);