Ejemplo n.º 1
0
    public void Throw()
    {
        GameObject newThrowableObject = Instantiate(throwables.gameObject, transform.position, Quaternion.identity);
        Throwable  throwable          = newThrowableObject.GetComponent <Throwable>();

        Vector2 throwVelocity = Vector2.Lerp(throwable.minThrowVelocity, throwable.maxThrowVelocity, Random.Range(0f, 1f));

        throwVelocity.x *= faceDir;

        throwable.Throw(throwVelocity);
    }
Ejemplo n.º 2
0
 /// <summary>
 /// If there is a throwable available, throw it forwards relative to the throwableSpawnLocation.
 /// </summary>
 /// <param name="direction"></param>
 /// <param name="force"></param>
 private void ThrowObject(float force)
 {
     if (throwableInHand != null)
     {
         Vector3 direction = throwableSpawnController.transform.forward;
         direction = Vector3.Lerp(direction, throwableSpawnHand.transform.forward, handControllerWeight);
         throwableInHand.Throw(direction, force);
         throwableInHand.transform.SetParent(null);
         throwableInHand = null;
     }
 }
Ejemplo n.º 3
0
    public void Throw(float curPower)
    {
        lastPower = curPower * powerMultiplier;
        recoilDir = (recoilPoint.position - cam.transform.position).normalized * (lastPower / dampeningRecoilPower);

        Throwable heldItem = cam.GetComponentInChildren <Throwable>();

        if (heldItem != null)
        {
            rb.AddForce(recoilDir, ForceMode.Impulse);
            heldItem.Throw(lastPower);
        }
    }
Ejemplo n.º 4
0
    public override void Pending()
    {
        instigator.DoMoveThrow();

        GameObject bomb = instigator.AbilityWantsObject("P_ThrowableBomb", instigator.transform.position + spawnOffset);

        Throwable throwable = bomb.GetComponent <Throwable>();

        if (throwable != null)
        {
            throwable.Throw(instigator, tossSpeedHorz, tossSpeedVert, instigator.GetFacingDirection());
        }

        base.Pending();
    }
Ejemplo n.º 5
0
    public void Throw(Vector2 force)
    {
        if (cooldownRemaining > 0 || !canShoot)
        {
            return;
        }

        Throwable spawnedThrowable = Throwable.Instantiate <Throwable>(currentThrowable);

        spawnedThrowable.transform.position = throwableSpawnPoint.position;
        spawnedThrowable.transform.forward  = force;
        spawnedThrowable.Throw(force, this);
        startCooldown     = (overrideCooldown < 0 ? ConfigManager.instance.cooldown : overrideCooldown) + additionalCooldown;
        cooldownRemaining = startCooldown;
    }
Ejemplo n.º 6
0
    private void Update()
    {
        if (dead)
        {
            return;
        }
        var inputPayload = playerConfig.PlayerInput.GetInput();
        var newVelocity  = new Vector2(0f, body.velocity.y);

        var newAimDirection = inputPayload.Aim;

        if (newAimDirection.x != 0 || newAimDirection.y != 0)
        {
            newAimDirection.Normalize();
            aimDirection = newAimDirection;
            crosshair.transform.localPosition = new Vector3(aimDirection.x * crosshairDistance, aimDirection.y * crosshairDistance, 0);
            _catch.SetAimDirection(aimDirection);
        }

        if (inputPayload.Throw)
        {
            if (item)
            {
                _animController.OnThrow();
                item.Throw(aimDirection * throwForce);
                item            = null;
                _catch.HeldItem = null;
            }
        }

        var grounded = Physics2D.Raycast(legs.position, -legs.up, 0.1f, platformLayerMask);

        if (grounded && inputPayload.Jump)
        {
            // Calculate the velocity required to achieve the target jump height.
            newVelocity.y = Mathf.Sqrt(2 * jumpHeight * Mathf.Abs(Physics2D.gravity.y));
            _animController.OnJump();
        }

        // Update the velocity assignment statements to use our selected
        // acceleration and deceleration values.
        newVelocity.x = speed * inputPayload.MoveHorizontal;
        body.velocity = newVelocity;

        // Set Animation state
        _animController.SetGrounded(grounded);
        _animController.ConfigByVelocity(newVelocity);
    }
Ejemplo n.º 7
0
    public override void Activate()
    {
        GameObject spear = instigator.AbilityWantsObject("P_FireBall", instigator.transform.position + spawnOffset);

        Throwable throwable = spear.GetComponent <Throwable>();

        if (throwable != null)
        {
            // determine how much lift to put in the throw, based on how far the player is

            throwable.Throw(instigator, tossSpeedHorz, baseTossSpeedVert, instigator.GetFacingDirection());
        }



        base.Activate();
    }
Ejemplo n.º 8
0
 /**
  * Call this method to throw the carried object into direction (or drop if direction is zero vector)
  */
 public void ThrowThrowable(Throwable throwable, Vector2 direction)
 {
     throwable.Throw(direction);
 }
Ejemplo n.º 9
0
    void Update()
    {
        if (_controller.isGrounded)
        {
            _velocity.y = 0;
        }

        if (Input.GetButton(_buttons[Button.RIGHT]))
        {
            normalizedHorizontalSpeed = 1;
            if (transform.localScale.x < 0f)
            {
                transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
            }

            if (_controller.isGrounded)
            {
                _animator.Play(Animator.StringToHash("Run"));
            }
            if (!runs)
            {
                SoundK = SoundKit.instance.playSoundLooped(run);
                runs   = true;
            }
        }
        else if (Input.GetButton(_buttons[Button.LEFT]))
        {
            normalizedHorizontalSpeed = -1;
            if (transform.localScale.x > 0f)
            {
                transform.localScale = new Vector3(-transform.localScale.x, transform.localScale.y, transform.localScale.z);
            }

            if (_controller.isGrounded)
            {
                _animator.Play(Animator.StringToHash("Run"));
            }
            if (!runs)
            {
                SoundK = SoundKit.instance.playSoundLooped(run);
                runs   = true;
            }
        }
        else
        {
            normalizedHorizontalSpeed = 0;

            if (_controller.isGrounded)
            {
                _animator.Play(Animator.StringToHash("Idle"));
            }
            if (runs)
            {
                runs = false;
                SoundK.stop();
            }
        }

        // move pickupObject
        if (isHolding)
        {
            pickedUpObject.transform.position = new Vector3(transform.position.x + (transform.localScale.x / 2), transform.position.y + 1, transform.position.z);;
        }

        // we can only jump whilst grounded
        if (_controller.isGrounded && Input.GetButtonDown(_buttons[Button.A]))
        {
            _velocity.y = Mathf.Sqrt(2f * jumpHeight * -gravity);
            _animator.Play(Animator.StringToHash("Jump"));
            SoundKit.instance.playOneShot(jump);
        }


        // apply horizontal speed smoothing it. dont really do this with Lerp. Use SmoothDamp or something that provides more control
        var smoothedMovementFactor = _controller.isGrounded ? groundDamping : inAirDamping;         // how fast do we change direction?

        _velocity.x = Mathf.Lerp(_velocity.x, normalizedHorizontalSpeed * runSpeed, Time.deltaTime * smoothedMovementFactor);

        // apply gravity before moving
        _velocity.y += gravity * Time.deltaTime;

        // if holding down bump up our movement amount and turn off one way platform detection for a frame.
        // this lets us jump down through one way platforms
        if (_controller.isGrounded && Input.GetButton(_buttons[Button.DOWN]))
        {
            _velocity.y *= 3f;
            _controller.ignoreOneWayPlatformsThisFrame = true;
        }

        _controller.move(_velocity * Time.deltaTime);

        // grab our current _velocity to use as a base for all calculations
        _velocity = _controller.velocity;

        if (Input.GetButtonDown(_buttons[Button.B]))
        {
            //TODO: b-button stuff!
            Debug.Log(_buttons[Button.B]);

            if (isHolding)
            {
                // if holding Throwable => Throw
                // calc force
                Vector2 force = new Vector2(transform.localScale.x * throwForce.x, throwForce.y);
                isHolding = false;
                pickedUpObject.Throw(force);
                pickedUpObject = null;
            }
            else
            {
                // if near Throwable => Pick up
                if (pickedUpObject != null)
                {
                    pickedUpObject.StartHolding();
                    isHolding = true;
                    // else => Punch
                }
                else
                {
                    // punch
                }
            }
        }
    }
Ejemplo n.º 10
0
    private void OnTriggerStay2D(Collider2D collision)
    {
        // TODO: Bugfixes with objects keeping held state and not working

        // If trigger collides with player and player interacts
        if (collision.CompareTag("Player") && player.interactInput)
        {
            Debug.Log("Changed hold state");
            // If object is not being held and player isn't holding something else, pick up
            if (!isBeingHeld && !throwableObj.wasJustPickedUp && !player.isHoldingObject)
            {
                Debug.Log("was just picked up");
                // Setting was just picked up (reset in object)
                throwableObj.wasJustPickedUp = true;
                throwableObj.PickUp(collision.gameObject);
                player.isHoldingObject = true;
            }
            // Else, if this is beign held, throw
            else if (isBeingHeld)
            {
                Debug.Log("was thrown");
                throwableObj.Throw();
                //StartCoroutine(WaitForNewPickup(player));
                player.isHoldingObject = false;
            }
            // Change held state (BUGS probably here!!)
            isBeingHeld              = !isBeingHeld;
            isBeingHeldByPlayer      = isBeingHeld;
            throwableObj.isBeingHeld = isBeingHeld;
        }
        // Else, if trigger collides with clone (and object is not being held by player TODO BUG: player might be holding another object)
        else if (collision.CompareTag("TimeClone") && !isBeingHeldByPlayer)
        {
            Clone clone         = collision.GetComponent <Clone>();
            bool  cloneInteract = clone.clonePositions[clone.posIndex].input.interactInput;
            if (cloneInteract)
            {
                Debug.Log("Changed hold state");
                // If object is not being held and player isn't holding something else, pick up
                if (!isBeingHeld && !throwableObj.wasJustPickedUp && !clone.isHoldingObject)
                {
                    Debug.Log("was just picked up");
                    // Setting was just picked up (reset in object)
                    throwableObj.wasJustPickedUp = true;
                    throwableObj.PickUp(collision.gameObject);
                    clone.isHoldingObject = true;
                }
                // Else, if this is beign held, throw
                else if (isBeingHeld)
                {
                    Debug.Log("was thrown");
                    throwableObj.Throw();
                    //StartCoroutine(WaitForNewPickup(player));
                    clone.isHoldingObject = false;
                }
                // Change held state (BUGS probably here!!)
                isBeingHeld = !isBeingHeld;
                throwableObj.isBeingHeld = isBeingHeld;
            }
        }
    }
Ejemplo n.º 11
0
    private void HandleInput()
    {
        if (Input.GetMouseButtonDown(0))
        {
            //hladame throwable objekt
            activeThrowable = FindThrowable();

            //ak sme ho nasli tak mu zavolame Attach
            if (activeThrowable != null)
            {
                activeThrowable.Attach();

                lastPosition = Camera.main.ScreenToViewportPoint(Input.mousePosition);
                lastTime     = Time.time;
            }
        }
        else if (Input.GetMouseButton(0))
        {
            lastPosition = Camera.main.ScreenToViewportPoint(Input.mousePosition);

            //ked pustime palec, tak sa zavola Dettach objektu throwable ktory mu zapne gravitaciu a spadne naspat nazem
            //zistujeme pohyb v priestore cez x,y poziciu mysi a z poziciu objektu relativne na kameru
            if (activeThrowable != null)
            {
                Vector3 position = Camera.main.ScreenToWorldPoint(Input.mousePosition + Vector3.forward * Mathf.Abs(Camera.main.transform.position.z - activeThrowable.transform.position.z));
                position.z = activeThrowable.transform.position.z;

                Vector3 dir = position - activeThrowable.transform.position;

                float velocityMultiplier = dir.magnitude / Time.deltaTime;

                Vector3 velocity = dir * velocityMultiplier;

                activeThrowable.GetRigidbody().velocity = velocity;


                lastPosition = Camera.main.ScreenToViewportPoint(Input.mousePosition);
                lastTime     = Time.time;
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            //ked pustime palec, tak sa zavola Dettach objektu
            if (activeThrowable != null)
            {
                float deltaTime = Time.time - lastTime;
                releasePosition = Camera.main.ScreenToViewportPoint(Input.mousePosition);


                Vector3 position = Camera.main.ScreenToWorldPoint(Input.mousePosition + Vector3.forward * Mathf.Abs(Camera.main.transform.position.z - activeThrowable.transform.position.z));
                position.z = activeThrowable.transform.position.z;

                Vector3 dir = position - activeThrowable.transform.position;

                if (dir.magnitude / deltaTime > minimalSwipeVelocity)
                {
                    Vector3 velocity = dir.normalized * throwMultiplier;

                    velocity.z = zVelocity;

                    activeThrowable.Throw(velocity);
                }

                activeThrowable.Dettach();
                activeThrowable = null;
            }
        }
    }