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.