Hello,
Im a bit new to programming and i have a little problem with my code and game mechanic.
What i am trying to do is:
I want to have my Character run constantly without having any acceleration.
I tried many Options, like the Constant Force 2D Component, but in every option there was it!
The Acceleration!
Right now i have an option that works with velocity and a Vector2.
But when i press space for jumping the character goes a little bit up then it resets instantly.
If someone has an Idea, it would be very great.
public class PlayerControllerAutoRun : MonoBehaviour {
public float jumpForce = 550;
private bool isRunning = true;
private bool jump = false;
private Rigidbody2D rb2d;
void Start()
{
rb2d = GetComponent<Rigidbody2D>()
}
void Update()
{
if (Input.GetButtonDown("Jump"))
jump = true;
if (isRunning)
{
rb2d.velocity = new Vector2(2, 0);
}
private void FixedUpdate()
{
float ver = Input.GetAxis("Vertical");
if (jump)
{
rb2d.AddForce(new Vector2(0, jumpForce));
jump = false;
}
}
}