Hello all, for some reason when I press spacebar and I try to jump, my player does not always jumps. Also when it does jump it kinda teleports to some point on the screen and then quickly falls down as if something really heavy pulls it down.
This is my script, it is really simple:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody2D Player;
public float movementSpeed;
public float jumpHeight;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
Player.velocity = new Vector2(movementSpeed * Input.GetAxis("Horizontal"), Player.position.y);
if (Input.GetButtonDown("Jump"))
{
Player.velocity = new Vector2(Player.position.x, jumpHeight);
}
}
}
My components that I have on the player:
I will be gratefull for any help. I really do not know why this is happening. If you want a demo of what is happening, I am willing to provide a video. I looked at other answers here, but they were about using FixedUpdate and I do not use it as you can see.