Unity how to add horizontal force to your rigidbody only. Vertical force gets applied

Viewed 23

im trying to add horizontal force to my player. But everytime I try, only Vertical force gets applied. My character shoots straight in the air but not to the left or right. I also tried adding way more force. Maybe im doing something wrong idk.

public class SpaceScript : MonoBehaviour
{
    public GameObject Player;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        Rigidbody2D Player1 = Player.GetComponent<Rigidbody2D>();

        Player1.AddForce(new Vector2(10, 10), ForceMode2D.Impulse);

    }
1 Answers

To eject the player into one direction (x-axis) you need way more force than pushing him in the air (y-axis) and I deleted , ForceMode2D.Impulse).Now it works perfectly fine.

Related