my parallax accelerate in unity2D when he has a new position

Viewed 44

i'm quite new with unity, and i try to do a "flappy bird" where my obstacl is a parallax.

But i don't understand why.

When my object.x is on "-10", i just want to move it to object.x = 10.

There is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class gotoleft : MonoBehaviour
{

    public Vector3 jump;
    public float jumpForce = 0f;

    public bool isGrounded;
    Rigidbody2D rb;
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        jump = new Vector3(-1.0f, 0.0f, 0.0f);
        Debug.Log("X: " + rb.transform.position);

    }


    void FixedUpdate()
    {

            rb.AddForce(jump * jumpForce * Time.deltaTime, ForceMode2D.Impulse);

            if (rb.transform.position.x <= -40)
            {
                Debug.Log("OUAIS MEC");

                 rb.transform.position = new Vector3(10, 3.0, 0.0);


        }

    }
}


the position of my object is okay, but it accelerates.

If someone can explains me, thanks I searched on the unity doc, but i still have the same pb.

Thanks for your answers.

2 Answers

If you making "flappy bird", basically you do not need to move bird itself. You must move obstacles and bg elements.

I do not see rest of your code but most likely you moving bird, what means what when your bird will fly over +40 units on "X" all your obstacle moves will become outside current camera position.

Divide by the distance if you need only a simple parallax effect.

Make adjustments as you need.

Worth checking in Wikipedia "Perspective Projection" in the "Formula" section.

Related