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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Drag Finger To Aim,Release To Shoot

Discussion in '2D' started by RajRajRaj, Oct 17, 2015.

  1. RajRajRaj

    RajRajRaj

    Joined:
    Aug 31, 2015
    Posts:
    42
    Hye there i m making a simple Shooting Game but its not like FPS(First Person) shooting game..

    it is simple 2d (Mobile game) where if we touch anywhere on screen player aim at that point and a Aiming arrow is also appear and when we release it shoots the bullet....

    i know I can make that with the help of OnPointerDown , OnDrag , OnPointerUp function but because i m beginer i cant code that properly i tried but failed every time....
    and one more thing bullet has rigidbody so we only have to addfore in the direction of pointer released plz helpme out.....

    if there is any Video Tutorial availabe similar to my Problem then plz send me link...

    i will be thankfull n appricate u in advance for my help :)
    u can Better understand with photos that i attached what i m trying to do....

    1.jpg 2.png
     
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    1. when the user presses the screen, store the position firstPressLocation
    2. when the user releases the finger store lastPressLocation and do the following:

    - calculate the velocity by vel = (lastPressLocation-firstPressLocation).normalized * speed

    Improving it so a small drag fires less would be to also multiply it by screen height or other fixed factor. Personally, I use units and never go into screen space so I would have converted the touch into world space first for resolution independence.

    But good luck. It's a trivial problem.
     
    theANMATOR2b likes this.
  3. RajRajRaj

    RajRajRaj

    Joined:
    Aug 31, 2015
    Posts:
    42

    for u its trivial :-(
    i m beginer....
    in unity and in coding tooo :-(
    is there any video tutorial available?
     
  4. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
  5. RajRajRaj

    RajRajRaj

    Joined:
    Aug 31, 2015
    Posts:
    42
  6. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    sorry to disappoint you, but you asked twice about video tutorial - nowhere did you mention that you have already watched that very same official tutorial video. So I provided it. I don't have any other tutorial for you however.
     
  7. RajRajRaj

    RajRajRaj

    Joined:
    Aug 31, 2015
    Posts:
    42

    ok i can u help me out how i can add fucntion to prepredict the projectile thoughing location like real AngryBirdGame...

    only help me that else all i manage :)
     
  8. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
  9. RajRajRaj

    RajRajRaj

    Joined:
    Aug 31, 2015
    Posts:
    42
  10. eses

    eses

    Joined:
    Feb 26, 2013
    Posts:
    2,637
    RajRajRaj: NP, and if you come up with proper solution please do share it here.
     
  11. RajRajRaj

    RajRajRaj

    Joined:
    Aug 31, 2015
    Posts:
    42
    yup n i m thinking to make videos on all that type of thing n upload on You Tube for the beginers like me to help them out with the help of unity and there great priceless helps :)

    i luv unity really its awsom
     
  12. Vicky153

    Vicky153

    Joined:
    Jul 10, 2018
    Posts:
    1
     
  13. KamalGames

    KamalGames

    Joined:
    Feb 6, 2019
    Posts:
    1

    Hello Raj,

    Did you able to get through this. I am also a beginner and i am trying do the same thing. please share any video or information do you have it will be great help from you

    Thanks in advance
     
  14. Lostwanderer1

    Lostwanderer1

    Joined:
    Mar 11, 2019
    Posts:
    27
    How do we do it in 3d?