コード例 #1
0
    void HandleKeyboardMouseInputs()
    {
        // always reset buffer to JumpBufferTime if not grounded
        if (!controller.isGrounded)
        {
            jumpBuffer = JumpBufferTime;
        }

        if (needToJump && jumpBuffer <= 0)
        {
            controller.AddForce(new Vector3(0, (float)Math.Sqrt(Physics.gravity.y * -2 * JumpDistance), 0), ForceMode.Impulse, this);
        }

        needToJump  = false;
        jumpBuffer -= Time.fixedDeltaTime;

        // if direction changes
        if (zDirection == 0 && controller.isGrounded)
        {
            controller.SetVelocity(new Vector3(rig.velocity.x, rig.velocity.y, 0), this);
        }
        else
        {
            if (rig.velocity.z == 0 || rig.velocity.z * zDirection < 0)
            {
                controller.SetVelocity(new Vector3(rig.velocity.x, rig.velocity.y, 0), this, false);
                controller.AddForce(new Vector3(0, 0, zDirection * InitialSpeed * (controller.isGrounded ? 1 : 0.5f)), ForceMode.VelocityChange, this);
            }
            var vel = new Vector3(0, 0, zDirection * Accel * (controller.isGrounded ? 1 : 0.5f));
            rig.AddForce(vel, ForceMode.Acceleration);
        }
    }
コード例 #2
0
    void ProcessGrappleTo()
    {
        if (grappleTo == null)
        {
            return;
        }

        var src = transform.position;
        var dst = grappleTo.transform.position;

        float distance = Vector3.Distance(src, dst);

        if (distance < StopThreshold)
        {
            grappleTo = null;
        }

        controller.AddForce(dst - src, ForceMode.Acceleration, this);
    }
コード例 #3
0
ファイル: JumpPad.cs プロジェクト: Brilath/Area-of-Ares
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.gameObject.tag == "Player")
        {
            Debug.Log("Launch player");
            MovementController movementController = other.gameObject.GetComponent <MovementController>();
            PhotonView         photonV            = other.gameObject.GetComponent <PhotonView>();

            if (photonV.IsMine && movementController != null)
            {
                movementController.AddForce(_jumpForce);
            }

            if (PhotonNetwork.IsMasterClient)
            {
                _animator.SetTrigger("launch");
            }
            _audio.Play();
        }
    }