Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How to make an arrow follow natural arc?

Discussion in '2D' started by StellaFerox, Apr 28, 2020.

  1. StellaFerox

    StellaFerox

    Joined:
    Apr 11, 2020
    Posts:
    2
    Hi all,

    I am an absolute beginner. I managed to create an arrow with a Rigidbody2D that I want to shoot from a bow by instantiating it in the update by pressing SPACE

    void Update()
    {
    if (Input.GetKeyDown(KeyCode.Space))
    {
    Instantiate(arrow, transform.position, transform.rotation);
    }
    }

    This works fine. However I cannot succeed in adding a launching force and let it fly a natural curve.
    I tried
    arrow.GetComponent<Rigidbody2D>().AddForce(Vector2.right * launchForce);
    after the instantiate-line but it cause the arrow to drop down. I serialized the LaunchForce but nothing happens.

    What am I doing wrong?

    thanks in advance for your knowledge....
     
  2. nabrown

    nabrown

    Joined:
    Jun 27, 2019
    Posts:
    27
    Can you provide the full Update() function when you had the AddForce in there? Also, what is your launchForce set to?
     
  3. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    Hi @StellaFerox

    Please use code tags when posting code. You can edit your post with edit button.
    https://forum.unity.com/threads/using-code-tags-properly.143875/

    "...but it cause the arrow to drop down."

    Are you sure you add enough force?

    There also exists two different force modes which you can add as AddForce's second paramater.

    Also, you could as well set the Rigidbody2d's velocity, so it starts with a certain velocity.