private void LateUpdate()
    {
        Vector3 deltaMovement = cameraTransform.position - lastCameraPosition;

        transform.position += ppuCam.RoundToPixel(new Vector3(deltaMovement.x * parallaxEffectMultiplier.x, deltaMovement.y * parallaxEffectMultiplier.y));
        lastCameraPosition  = cameraTransform.position;

        if (infiniteHorizontal)
        {
            if (Mathf.Abs(cameraTransform.position.x - transform.position.x) >= textureUnitSizeX)
            {
                float offsetPositionX = (cameraTransform.position.x - transform.position.x) % textureUnitSizeX;
                transform.position = ppuCam.RoundToPixel(new Vector3(cameraTransform.position.x + offsetPositionX, transform.position.y));
            }
        }

        if (infiniteVertical)
        {
            if (Mathf.Abs(cameraTransform.position.y - transform.position.y) >= textureUnitSizeY)
            {
                float offsetPositionY = (cameraTransform.position.y - transform.position.y) % textureUnitSizeY;
                transform.position = ppuCam.RoundToPixel(new Vector3(transform.position.x, cameraTransform.position.y + offsetPositionY));
            }
        }
    }
Пример #2
0
 // Update is called once per frame
 void Update()
 {
     if (isOn)
     {
         // transform.position = (Vector2)player.position + offset;
         transform.position = pixCam.RoundToPixel((Vector2)player.position + offset);
         //r.transform.localPosition = pixCam.RoundToPixel(r.transform.localPosition);
     }
 }
Пример #3
0
    // Update is called once per frame
    void LateUpdate()
    {
        Vector3 npos = target.position;

        npos   = p.RoundToPixel(npos);
        npos.z = transform.position.z;

        Vector3 tpos = Vector3.MoveTowards(transform.position, npos, Time.deltaTime * 3.2f);

        tpos = p.RoundToPixel(tpos);


        transform.position = tpos;
    }
 void LateUpdate()
 {
     if (pixelPerfectCamera != null)
     {
         transform.position = pixelPerfectCamera.RoundToPixel(transform.position);
     }
 }
Пример #5
0
    public void Move()
    {
        float delta = Time.deltaTime;


        if (move)
        {
            if (MoveType)
            {
                body.velocity = InputVel * speed;
            }
            else
            {
                Vector2 nPos = (Vector2)transform.position + InputVel * speed * delta;



                //If Pixel Perfect Movement is required
                if (pixCam)
                {
                    nPos = pixCam.RoundToPixel(nPos);
                }



                body.MovePosition(nPos);
            }
        }
    }
Пример #6
0
    public void Move(Vector2 moveDelta)
    {
        float delta = Time.deltaTime;

        if (useUnscaledTime)
        {
            delta = Time.unscaledDeltaTime;
        }

        moveDelta = moveDelta * speed;

        //Debug.DrawRay((Vector2)transform.position + moveDelta.normalized * 0.16f, moveDelta,Color.red);


        RaycastHit2D b = Physics2D.Raycast((Vector2)transform.position + Vector2.right * (0.16f * Mathf.Sign(moveDelta.x)), Vector2.right * moveDelta.x, speed, 1 << LayerMask.NameToLayer("MDW"));
        RaycastHit2D c = Physics2D.Raycast((Vector2)transform.position + Vector2.up * (0.16f * Mathf.Sign(moveDelta.y)), Vector2.up * moveDelta.y, speed, 1 << LayerMask.NameToLayer("MDW"));

        Debug.DrawRay((Vector2)transform.position + Vector2.right * (0.16f * Mathf.Sign(moveDelta.x)), Vector2.right * (3 * Mathf.Sign(moveDelta.x)), Color.red);
        Debug.DrawRay((Vector2)transform.position + Vector2.up * (0.16f * Mathf.Sign(moveDelta.y)), Vector2.up * (3 * Mathf.Sign(moveDelta.y)), Color.red);

        if (b.collider)
        {
            if (!b.collider.isTrigger)
            {
                Debug.DrawRay((Vector2)transform.position + Vector2.right * (0.16f * Mathf.Sign(moveDelta.x)), Vector2.right * (3 * Mathf.Sign(moveDelta.x)), Color.yellow);
                DEBUG_RAY_X = b.point;
                DRX         = b.distance;

                if (b.distance <= 0.126f + skin)
                {
                    moveDelta.x = 0;
                }
            }
        }

        if (c.collider)
        {
            if (!c.collider.isTrigger)
            {
                Debug.DrawRay((Vector2)transform.position + Vector2.up * (0.16f * Mathf.Sign(moveDelta.y)), Vector2.up * (3 * Mathf.Sign(moveDelta.y)), Color.yellow);

                DEBUG_RAY_Y = c.point;
                DRY         = c.distance;

                if (c.distance <= 0.126f + skin)
                {
                    moveDelta.y = 0;
                }
            }
        }

        transform.Translate(moveDelta * delta);

        if (pixelCam)
        {
            transform.position = pixelCam.RoundToPixel(transform.position);
        }
    }
    // LateUpdate is called once per frame after all Update functions have been called
    void LateUpdate()
    {
        // Check whether transform has changed
        if (transform.hasChanged)
        {
            // Set target position
            Vector2 targetPosition;
            if (transform.parent != null)
            {
                targetPosition = (Vector2)transform.parent.position + (Vector2)pixelPerfectCamera.RoundToPixel(transform.localPosition);
            }
            else
            {
                targetPosition = transform.position;
            }

            // Snap to pixel grid
            transform.position   = pixelPerfectCamera.RoundToPixel(targetPosition);
            transform.hasChanged = false;
        }
    }
Пример #8
0
        void Update()
        {
            if (camera != null)
            {
                t = Mathf.Clamp01(t + (direction * Time.deltaTime / animationDuration));

                animationOffset = Vector2.LerpUnclamped(hideOffset, Vector3.zero, curve.Evaluate(t));
                var p = (Vector2)camera.ViewportToWorldPoint(anchor + offset + animationOffset);
                transform.position = p;
                if (pixelPerfectCamera != null && Application.isPlaying)
                {
                    transform.position = pixelPerfectCamera.RoundToPixel(transform.position);
                }
            }
        }
Пример #9
0
        /// <summary>
        /// Scroll the background horizontally to the left by a certain number of screens.
        /// </summary>
        /// <param name="screens">The number of screens to scroll left.</param>
        /// <param name="speed">The speed at which to scroll the background.</param>
        /// <param name="movingTransforms">An array of transforms that should move with the background.</param>
        /// <param name="ScrollCompleteAction">An action to perform once the scroll has completed.</param>
        private IEnumerator ScrollBackground(int screens, float speed, Transform[] movingTransforms, Action ScrollCompleteAction)
        {
            if (screens <= 0)
            {
                yield break;
            }

            IsScrolling = true;
            OnScrollStart?.Invoke(this, EventArgs.Empty);
            int screensScrolled = 0;

            do
            {
                // Move background
                transform.Translate(Vector2.left * speed * Time.deltaTime);

                // Loop background when it passes the start position
                if (transform.position.x < -startPosition.x)
                {
                    Vector2 newPosition = startPosition;
                    newPosition.x     -= (-startPosition.x - transform.position.x);
                    transform.position = newPosition;
                    screensScrolled++;
                }

                // Move objects with background
                foreach (Transform movingTransform in movingTransforms)
                {
                    movingTransform.Translate(Vector2.left * speed * Time.deltaTime);
                }

                yield return(null);
            } while (screensScrolled < screens);

            // Make sure background is pixel perfect
            transform.position = pixelPerfectCamera.RoundToPixel(transform.position);

            IsScrolling = false;
            OnScrollComplete?.Invoke(this, EventArgs.Empty);
            ScrollCompleteAction?.Invoke();
        }
Пример #10
0
 // Update is called once per frame
 void LateUpdate()
 {
     transform.localPosition = Vector3.zero;
     transform.position      = Camera.RoundToPixel(transform.position);
 }
Пример #11
0
        // Update is called once per frame
        void Update()
        {
            //Debug.Log(body.angularVelocity);
            //Debug.Log(body.velocity);
            //body.velocity = Vector2.zero;

            if (specialmode)
            {
                mouse.MoveSpring();
                //spring.transform.position = mouse.mousePos;
                //spring.GetComponent<Rigidbody2D>().MovePosition(mouse.mousePos);

                //spring.GetComponent<Rigidbody2D>().MovePosition(Vector2.MoveTowards(spring.transform.position, mouse.mousePos+offset, Time.deltaTime * power));
            }

            if (ready)
            {
                if (!specialmode)
                {
                    //shadow.transform.position = (Vector2)teleObject.position + Vector2.down;

                    //if (ready)
                    //teleObject.position = (Vector2)transform.position + Vector2.up;


                    if (!aim)
                    {
                        body.velocity = Vector2.zero;
                        //body.MovePosition(Vector2.MoveTowards(transform.position, mouse.mousePos + offset, Time.deltaTime * power));
                        body.MovePosition(Vector2.MoveTowards(transform.position, pixcam.RoundToPixel(mouse.mousePos + offset), Time.deltaTime * power));
                        //transform.position= Vector2.MoveTowards(transform.position, mouse.mousePos + offset, Time.deltaTime * 5);
                        Debug.DrawLine(transform.position, mouse.mousePos + offset, Color.red);

                        Vector2 dir = (Vector2)transform.position - lastPos;

                        if (dir != Vector2.zero)
                        {
                            lastDir = dir.normalized;
                        }

                        lastPos = transform.position;
                    }
                    else
                    {
                        lastDir       = (mouse.mousePos - (Vector2)transform.position).normalized;
                        body.velocity = Vector2.zero;
                        if (ThrowIndicator)
                        {
                            float angle = Mathf.Atan2(lastDir.y, lastDir.x) * Mathf.Rad2Deg;

                            ThrowIndicator.rotation = Quaternion.Euler(0, 0, angle);
                        }
                    }


                    Debug.DrawRay(transform.position, lastDir, Color.red);
                }
                else
                {
                    shadow.transform.position = (Vector2)teleObject.position + Vector2.down;

                    if (aim)
                    {
                        lastDir       = (mouse.mousePos - (Vector2)transform.position).normalized;
                        body.velocity = Vector2.zero;
                        if (ThrowIndicator)
                        {
                            float angle = Mathf.Atan2(lastDir.y, lastDir.x) * Mathf.Rad2Deg;

                            ThrowIndicator.rotation = Quaternion.Euler(0, 0, angle);
                        }
                    }
                }
            }
        }