예제 #1
0
    void OnCollisionEnter2D(Collision2D col)
    {
        Vector2 thisPos = gameObject.transform.position;

        if (col.gameObject.tag == "Player" && playerScript.partConfiguration != 2 && playerScript.isGrounded == true && !(playerScript.partConfiguration == 1 && playerScript.scaler && playerScript.scalerTrueGrounded)) // reset the collider if the player is not jumping
        {
            playerBoxCol.enabled = false;
            playerBoxCol.enabled = true;
        }
        else if (col.gameObject.tag == "Player" && (!playerScript.isGrounded || playerScript.partConfiguration == 2 || (playerScript.partConfiguration == 1 && playerScript.scaler && !playerScript.scalerTrueGrounded)) && playerScript.partConfiguration != 3 && playerScript.partConfiguration != 4)
        {
            playerScript.legString = this.name;
            int playerParts = playerScript.partConfiguration;
            if (attached == false && playerParts != 3 && playerParts != 4 && unavailableTimer > 0.3f)
            {
                col.gameObject.transform.rotation = Quaternion.identity;
                if (playerParts == 1)
                {
                    thisPos.y += 0.014f;
                    col.gameObject.transform.position = thisPos;
                }
                else if (playerParts == 2)
                {
                    thisPos.y += 0.014f;
                    col.gameObject.transform.position = thisPos;
                }
                Attached();
                this.gameObject.transform.parent = col.transform;
                playerScript.UpdateParts();
            }
        }
    }
예제 #2
0
    void OnCollisionEnter2D(Collision2D col)
    {
        Vector2 thisPos = gameObject.transform.position;

        if (col.gameObject.tag == "Player" && (!playerScript.isGrounded || playerScript.partConfiguration == 3 || (playerScript.partConfiguration == 1 && playerScript.scaler && !playerScript.scalerTrueGrounded)) && playerScript.partConfiguration != 2 && playerScript.partConfiguration != 4) // if the player has just legs, snap anyway
        {
            playerScript.armString = this.name;
            int playerParts = playerScript.partConfiguration;
            if (attached == false && playerParts != 2 && playerParts != 4 && unavailableTimer > 0.3f)
            {
                col.gameObject.transform.rotation = Quaternion.identity;
                if (playerParts == 1) // this one needs changing
                {
                    thisPos.y += 0.01f;
                    col.gameObject.transform.position = thisPos;
                }
                Attached();
                this.gameObject.transform.parent   = col.transform;
                this.gameObject.transform.position = col.transform.position;
                playerScript.UpdateParts();
            }
        }
        else if (col.gameObject.tag == "Player" && playerScript.isGrounded == true)
        // this resets the collider, so that if the player is pushing against it and then jumps, they can still connect
        {
            playerBoxCol.enabled = false;
            playerBoxCol.enabled = true;
        }
        else if (col.gameObject.tag == "Legs")
        {
            // add options for legs to attach here
        }
    }
예제 #3
0
 void Update()
 {
     if (taken == true)
     {
         headPos            = head.transform.position;
         playerDistance     = Vector2.Distance(headPos, transform.position);
         timer             += Time.deltaTime;
         transform.position = Vector2.Lerp(transform.position, headPos, timer * 2.5f);
         if (timer > 0.4f || playerDistance < 0.1f)
         {
             playerScript.headString = headString;
             if (augmentType == augmentIdentifier.Scaler)
             {
                 playerScript.augmentScalerIdentifier = instance;
             }
             if (augmentType == augmentIdentifier.Hookshot)
             {
                 playerScript.augmentHookshotIdentifier = instance;
             }
             playerScript.UpdateParts();
             Destroy(gameObject);
         }
     }
     if (augmentType == augmentIdentifier.Scaler)
     {
         gameObject.transform.Rotate(Vector3.forward * 30f * Time.deltaTime);
     }
     else if (augmentType == augmentIdentifier.Hookshot)
     {
         secondSprite.transform.Rotate(Vector3.forward * 60f * -Time.deltaTime);
     }
 }
    // Update is called once per frame
    private void Update()
    {
        if (unlockOnInput && waypointCycling && waypointCyclingTimer > 1f && (InputManager.JoystickLeftVerticalRaw() != 0 || InputManager.JoystickLeftHorizontalRaw() != 0))
        {
            EndCycle();
            playerScript.UpdateParts();
        }

        if (!waypointCycling)    // when not cycling through waypoints
        {
            if (!lockView)
            {
                if (scouting)
                {
                    if (Input.GetAxisRaw("Horizontal") == 0 && Input.GetAxisRaw("Vertical") == 0)
                    {
                        if (scoutInputTimer < 0f)
                        {
                            scoutInputTimer = 0f;
                        }
                        rb.velocity      = Vector2.ClampMagnitude(rb.velocity, scoutInputTimer);
                        scoutInputTimer -= Time.deltaTime / scoutInputTime;
                    }
                    else
                    {
                        scoutInputTimer = 1f;
                        Vector2 input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
                        rb.AddForce(scoutAcceleration * input, ForceMode2D.Force);
                        rb.velocity = Vector2.ClampMagnitude(rb.velocity, scoutSpeedMax);
                        float maxScoutDistance = 30f;
                        transform.position = new Vector3(Mathf.Clamp(transform.position.x, target.position.x - maxScoutDistance, target.position.x + maxScoutDistance),
                                                         Mathf.Clamp(transform.position.y, target.position.y - maxScoutDistance, target.position.y + maxScoutDistance),
                                                         transform.position.z);
                    }
                }
            }


            if (damping <= 0f)
            {
                speedUp = false;
                damping = 0f;
            }
            else if (speedUp == true)
            {
                t      += Time.unscaledDeltaTime / 1f;
                damping = Mathf.SmoothStep(currentDamping, 0f, t);
            }

            if (slowDown == true && damping >= initialDamping)
            {
                damping  = initialDamping;
                slowDown = false;
            }
            else if (slowDown == true && damping < initialDamping)
            {
                t      += Time.unscaledDeltaTime / 1f;
                damping = Mathf.SmoothStep(currentDamping, initialDamping, t);
            }

            // only update lookahead pos if accelerating or changed direction
            float xMoveDelta = (target.position - m_LastTargetPosition).x;

            bool updateLookAheadTarget = Mathf.Abs(xMoveDelta) > lookAheadMoveThreshold;

            if (updateLookAheadTarget)
            {
                m_LookAheadPos = lookAheadFactor * Vector3.right * Mathf.Sign(xMoveDelta);
            }
            else
            {
                m_LookAheadPos = Vector3.MoveTowards(m_LookAheadPos, Vector3.zero, Time.deltaTime * lookAheadReturnSpeed);
            }

            Vector3 aheadTargetPos = target.position + m_LookAheadPos + Vector3.forward * m_OffsetZ;

            if (lockAxis)
            {
                if (lockY)
                {
                    aheadTargetPos.y = yLockPos;
                }
                if (lockX)
                {
                    aheadTargetPos.x = xLockPos;
                }
            }

            Vector3 newPos = new Vector3(Mathf.SmoothDamp(transform.position.x, aheadTargetPos.x, ref m_CurrentVelocity.x, initialDamping),
                                         Mathf.SmoothDamp(transform.position.y, aheadTargetPos.y, ref m_CurrentVelocity.y, damping),
                                         Mathf.SmoothDamp(transform.position.z, aheadTargetPos.z, ref m_CurrentVelocity.z, damping));

            if (!scouting && !float.IsNaN(newPos.y))
            {
                transform.position = newPos;
            }

            m_LastTargetPosition = target.position;

            if (shakeDuration > 0)
            {
                transformPos.localPosition = transformPos.position + Random.insideUnitSphere * shakeMagnitude;
                shakeDuration  -= Time.unscaledDeltaTime;
                shakeMagnitude -= Time.unscaledDeltaTime;
            }
            else
            {
                shakeDuration = 0f;
                transformPos.localPosition = transformPos.position;
            }
        }
        else if (waypointCycling)                      // waypoint cycling
        {
            waypointCyclingTimer += Time.deltaTime;    // track overall time

            waypointMoveTimer += Time.deltaTime;       // track time of each position
            if (waypointMoveTimer >= waypointMoveTime) // move to position
            {
                waypointMoveTimer = waypointMoveTime;

                if (lockView)
                {
                    Vector2 screenPoint = camera.WorldToViewportPoint(target.position);
                    bool    onScreen    = screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
                    if (!onScreen)
                    {
                        EndCycle();
                        playerScript.UpdateParts();
                    }
                }
                else
                {
                    waypointPauseTimer += Time.deltaTime;     // track stay time at each position - if lockView is on, it will stay here, so the timer stops
                }

                if (waypointPauseTimer > waypointPauseTime)
                {
                    waypointPauseTimer = waypointPauseTime;
                    waypointCounter++;
                    if (waypointCounter == waypointCount)
                    {
                        EndCycle();
                    }
                    else
                    {
                        camPoint.NextCoordinate();
                    }
                }
            }
            gameObject.transform.position = Vector3.Lerp(previousWaypointPos, wayPointPos, waypointMoveTimer / waypointMoveTime);
        }

        // resize is always on

        if (resize == true)
        {
            if (resizeTimer < 1f)
            {
                resizeTimer += Time.deltaTime / resizeDuration;
            }
            else
            {
                resizeTimer = 1f;
                resize      = false;
            }
            camera.orthographicSize = Mathf.Lerp(initialCameraSize, targetCameraSize, resizeTimer);
        }
    }
 void Update()
 {
     playerScript.UpdateParts(); // get player to update parts, recognising the new ones
     gameObject.SetActive(false);
 }