How Can i Make Bow/Arrow System for my 2D Platformer Game?

Hello my friends, i could not find any tutorial. I don’t want drag mouse when shoot. I want only click and hold like this video:

Please, help. Have a nice day.

I don’t understand, exactly. Is that a video of what you have or want?
Don’t want drag … not sure what that is.

If that’s not your project in the video, then what have you tried, so far?

I want to learn shooting arrow system like this video. But, i could not find anything. If there are tutorials or example projects, it could be enough to help understanding the system.

Increase a variable indicating the power of the shot the longer the mouse is down. When you release the mouse, fire the arrow with a velocity multiplied by the power variable.

2 Likes

To follow on from what groZZler said: Give the arrow a rigidbody, use the forcemode impulse to trigger the initial velocity.

If the arrow hits a surface bury it slightly into the surface by moving it slightly forwards along its moving axis & disable the rigidbody.

The pulling back of the arrow will just be an animation that is linked to a value through the animation controller.

Thanks for replies my friends but i am still beginner about c#. I can not do what you say. I downloaded it:
https://www.assetstore.unity3d.com/en/#!/content/32783

I changed “Vector2 mousePos = new Vector2(transform.position.x-posX,transform.position.y-posY);” to “Vector2 mousePos = new Vector2(posX,posY);”
But it does not still like i want. I want to shoot arrow by clicking as 45 degree to right or left when character look right or left. Sorry for my english. I think i will not do :frowning:

    public void prepareArrow() {
        // get the touch point on the screen
        mouseRay1 = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(mouseRay1, out rayHit, 1000f) && arrowShot == false)
        {
            // determine the position on the screen
            posX = this.rayHit.point.x;
            posY = this.rayHit.point.y;
            // set the bows angle to the arrow
            Vector2 mousePos = new Vector2(transform.position.x-posX,transform.position.y-posY);
            float angleZ = Mathf.Atan2(mousePos.y,mousePos.x)*Mathf.Rad2Deg;
            transform.eulerAngles = new Vector3(0,0,angleZ);
            // determine the arrow pullout
            length = mousePos.magnitude / 3f;
            length = Mathf.Clamp(length,0,1);
            // set the bowstrings line renderer
            stringPullout = new Vector3(-(0.44f+length), -0.06f, 2f);
            // set the arrows position
            Vector3 arrowPosition = arrow.transform.localPosition;
            arrowPosition.x = (arrowStartX - length);
            arrow.transform.localPosition = arrowPosition;
        }
        arrowPrepared = true;
    }

Delete them:

            Vector2 mousePos = new Vector2(transform.position.x-posX,transform.position.y-posY);
            float angleZ = Mathf.Atan2(mousePos.y,mousePos.x)*Mathf.Rad2Deg;

Paste them and this codes do better it.

            Vector3 mousePos = Camera.main.ScreenToWorldPoint (Input.mousePosition) - transform.position;
            difference.Normalize ();

            float angleZ = (Mathf.Atan2 (mousePos.y, mousePos.x) * Mathf.Rad2Deg); 
            transform.rotation = Quaternion.Euler (0f, 0f, rotZ);
1 Like