Ejemplo n.º 1
0
    void GetInput()
    {
        input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
        if (!jones.isGrounded)
        {
            input.x /= 2;
        }

        input = Vector2.ClampMagnitude(input, 1);
    }
Ejemplo n.º 2
0
    void Dragging()
    {
        Vector2 draggingPos  = Camera.main.ScreenToWorldPoint(touch.position);
        Vector2 resultVector = Vector2.ClampMagnitude(
            new Vector2(draggingPos.x - dragStartPos.x, draggingPos.y - dragStartPos.y), maxDrag);

        lr.positionCount = 2;
        lr.SetPosition(1, new Vector2(
                           resultVector.x + dragStartPos.x, resultVector.y + dragStartPos.y));
    }
Ejemplo n.º 3
0
    void DragRelease()
    {
        lr.positionCount = 0;
        Vector2 dragReleasePos = Camera.main.ScreenToWorldPoint(touch.position);

        Vector2 force        = dragStartPos - dragReleasePos;
        Vector2 clampedForce = Vector2.ClampMagnitude(force, maxDrag) * power;

        rb.AddForce(clampedForce, ForceMode2D.Impulse);
    }
Ejemplo n.º 4
0
 /** Calculates how far to move during a single frame */
 protected Vector2 CalculateDeltaToMoveThisFrame(Vector2 position, float distanceToEndOfPath, float deltaTime)
 {
     if (rvoController != null && rvoController.enabled)
     {
         // Use RVOController to get a processed delta position
         // such that collisions will be avoided if possible
         return(movementPlane.ToPlane(rvoController.CalculateMovementDelta(movementPlane.ToWorld(position.ToPFV2(), 0).ToUnityV3(), deltaTime).ToPFV3()).ToUnityV2());
     }
     // Direction and distance to move during this frame
     return(Vector2.ClampMagnitude(velocity2D * deltaTime, distanceToEndOfPath));
 }
Ejemplo n.º 5
0
    public void OnDrag(PointerEventData eventData)
    {
        attack.GetComponent <Image>().enabled = true;

        pointB = new Vector2(eventData.position.x, eventData.position.y);

        offset = pointB - pointA;
        Vector2 direction = Vector2.ClampMagnitude(offset, radius);

        joystick.transform.position = new Vector2(pointA.x + direction.x, pointA.y + direction.y);
        attack.transform.position   = new Vector2(pointA.x + direction.normalized.x * radius, pointA.y + direction.normalized.y * radius);
    }
Ejemplo n.º 6
0
    void Update()
    {
        // check velocity
        if (rb.velocity.magnitude > maxSpeed)
        {
            rb.velocity = Vector2.ClampMagnitude(rb.velocity, maxSpeed);
        }

        if (Input.GetMouseButtonDown(0) && bounce >= 1)
        {
            pressDown.Play(0);
            pressDown.pitch = 0.3f;
            startPoint      = camera.ScreenToWorldPoint(Input.mousePosition);
            startPoint.z    = 15;
        }
        if (Input.GetMouseButton(0) && bounce >= 1)
        {
            Vector3 currentPoint = camera.ScreenToWorldPoint(Input.mousePosition);
            currentPoint.z = 15;
            DrawLine(startPoint, currentPoint);
        }

        if (Input.GetMouseButtonUp(0) && bounce >= 1)
        {
            pressDown.pitch = 0.6f;
            release.Play(0);

            bounce -= 1;
            endLine();

            endPoint   = camera.ScreenToWorldPoint(Input.mousePosition);
            endPoint.z = 15;

            ballForce = new Vector2(
                Mathf.Clamp(startPoint.x - endPoint.x, minPower.x, maxPower.x),
                Mathf.Clamp(startPoint.y - endPoint.y, minPower.y, maxPower.y));
            rb.AddForce(ballForce * power, ForceMode2D.Impulse);
        }
    }
Ejemplo n.º 7
0
        /** Called during either Update or FixedUpdate depending on if rigidbodies are used for movement or not */
        protected override void MovementUpdateInternal(float deltaTime, out Vector3 nextPosition, out Quaternion nextRotation)
        {
            float currentAcceleration = maxAcceleration;

            // If negative, calculate the acceleration from the max speed
            if (currentAcceleration < 0)
            {
                currentAcceleration *= -maxSpeed;
            }

            if (updatePosition)
            {
                // Get our current position. We read from transform.position as few times as possible as it is relatively slow
                // (at least compared to a local variable)
                simulatedPosition = tr.position;
            }
            if (updateRotation)
            {
                simulatedRotation = tr.rotation;
            }

            var currentPosition = simulatedPosition;

            // Update which point we are moving towards
            interpolator.MoveToCircleIntersection2D(currentPosition, pickNextWaypointDist, movementPlane);
            var dir = movementPlane.ToPlane(steeringTarget - currentPosition);

            // Calculate the distance to the end of the path
            float distanceToEnd = dir.magnitude + Mathf.Max(0, interpolator.remainingDistance);

            // Check if we have reached the target
            var prevTargetReached = reachedEndOfPath;

            reachedEndOfPath = distanceToEnd <= endReachedDistance && interpolator.valid;
            if (!prevTargetReached && reachedEndOfPath)
            {
                OnTargetReached();
            }
            float slowdown;

            // Normalized direction of where the agent is looking
            var forwards = movementPlane.ToPlane(simulatedRotation * (rotationIn2D ? Vector3.up : Vector3.forward));

            // Check if we have a valid path to follow and some other script has not stopped the character
            if (interpolator.valid && !isStopped)
            {
                // How fast to move depending on the distance to the destination.
                // Move slower as the character gets closer to the destination.
                // This is always a value between 0 and 1.
                slowdown = distanceToEnd < slowdownDistance?Mathf.Sqrt(distanceToEnd / slowdownDistance) : 1;

                if (reachedEndOfPath && whenCloseToDestination == CloseToDestinationMode.Stop)
                {
                    // Slow down as quickly as possible
                    velocity2D -= Vector2.ClampMagnitude(velocity2D, currentAcceleration * deltaTime);
                }
                else
                {
                    velocity2D += MovementUtilities.CalculateAccelerationToReachPoint(dir.ToUnityV2(), dir.normalized * maxSpeed, velocity2D, currentAcceleration, rotationSpeed, maxSpeed, forwards) * deltaTime;
                }
            }
            else
            {
                slowdown = 1;
                // Slow down as quickly as possible
                velocity2D -= Vector2.ClampMagnitude(velocity2D, currentAcceleration * deltaTime);
            }

            velocity2D = MovementUtilities.ClampVelocity(velocity2D, maxSpeed, slowdown, slowWhenNotFacingTarget, forwards.ToUnityV2());

            ApplyGravity(deltaTime);

            if (rvoController != null && rvoController.enabled)
            {
                // Send a message to the RVOController that we want to move
                // with this velocity. In the next simulation step, this
                // velocity will be processed and it will be fed back to the
                // rvo controller and finally it will be used by this script
                // when calling the CalculateMovementDelta method below

                // Make sure that we don't move further than to the end point
                // of the path. If the RVO simulation FPS is low and we did
                // not do this, the agent might overshoot the target a lot.
                var rvoTarget = currentPosition.ToPFV3() + movementPlane.ToWorld(Vector2.ClampMagnitude(velocity2D, distanceToEnd), 0f);
                rvoController.SetTarget(rvoTarget, velocity2D.magnitude, maxSpeed);
            }

            // Set how much the agent wants to move during this frame
            var delta2D = lastDeltaPosition = CalculateDeltaToMoveThisFrame(movementPlane.ToPlane(currentPosition), distanceToEnd, deltaTime);

            nextPosition = currentPosition + movementPlane.ToWorld(delta2D.ToPFV2(), verticalVelocity * lastDeltaTime).ToUnityV3();
            CalculateNextRotation(slowdown, out nextRotation);
        }
Ejemplo n.º 8
0
    void Update()
    {
        focusPosition = focusObject.transform.position;

        //camera up-down
        if (focusPosition.y >= up)
        {
            up   += 15f;
            down += 15f;
            transform.position += new Vector3(0, 15f, 0);
            //Debug.Log(up);
        }
        if (focusPosition.y < down)
        {
            up   -= 15f;
            down -= 15f;
            transform.position += new Vector3(0, -15f, 0);
        }
        //camera lef-right
        if (focusPosition.x <= left)
        {
            left  -= rightLeft;
            right -= rightLeft;
            transform.position += new Vector3(-rightLeft, 0, 0);
        }
        if (focusPosition.x > right)
        {
            left  += rightLeft;
            right += rightLeft;
            transform.position += new Vector3(rightLeft, 0, 0);
        }



        //down scene
        if (focusPosition.y < 73 && focusPosition.y > 12.5f && focusPosition.x < -145 && focusPosition.x > -166)
        {
            Vector3 distance     = focusPosition - (Vector2)transform.position;
            Vector3 moveDistance = Vector2.ClampMagnitude(distance, distance.magnitude - followDistance);
            transform.position += new Vector3(0, moveDistance.y, 0);
            change              = true;
        }

        if (change && focusPosition.y > 73)
        {
            change              = false;
            transform.position += new Vector3(0, +7.4f, 0);
        }
        if (change && focusPosition.y < 12.5)
        {
            change              = false;
            transform.position += new Vector3(0, +7.5f, 0);
        }

        //scalling to 4th lvl
        if (focusPosition.x < -197.5f && !changeSize)
        {
            startSpawn = true;
            Vector3 direction = focusObject.transform.localScale;
            focusObject.transform.localScale = direction.x < 0 ? new Vector3(-1, 1, 1) : new Vector3(1, 1, 1);
            PlayerController.rayCastSizeX    = 0;
            PlayerController.rayCastSizeY    = 0.28f;
            PlayerController.rayLength       = 0.64f;
            changeSize = true;
        }

        if (changeSize && focusPosition.x > -197.5f)
        {
            startSpawn = false;
            Vector3 direction = focusObject.transform.localScale;
            focusObject.transform.localScale = direction.x < 0 ? new Vector3(-1.37f, 1.37f, 1.37f) : new Vector3(1.37f, 1.37f, 1.37f);
            PlayerController.rayCastSizeX    = 0.11f;
            PlayerController.rayCastSizeY    = 0.18f;
            PlayerController.rayLength       = 0.9f;
            changeSize = false;
        }

        if (InCity() && !PauseMenu.GameIsPaused)
        {
            fog.enabled    = true;
            Time.timeScale = 0.5f;
        }
        else if (!PauseMenu.GameIsPaused)
        {
            fog.enabled    = false;
            Time.timeScale = 1;
        }


        if (end)
        {
            StartCoroutine(NewScene());
        }
    }