Search Unity

"Pull back and Release" Controls like (Golf Battle) by Miniclip

Discussion in 'Scripting' started by cohenburleson1, Mar 13, 2019.

  1. cohenburleson1

    cohenburleson1

    Joined:
    Mar 11, 2019
    Posts:
    5
    Hi i'm trying to make controls for my 3d game and i need to set up a "Pull back and release to shoot" mechanism for a ball. Right now i have a flat plain area and i have a ball on it, all i want the ball to be able to do is be able to pull back on it and release for it to shoot forward. Also if you could show how to make an arrow that shows the direction its going in aswell, Im a beginner in unity so any help is great from the community!
    Could someone possibly make a tutorial on this or tell me step by step what to check or what to do. and provide a script.
     
  2. eses

    eses

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

    "Could someone possibly make a tutorial"

    I bet that you will be waiting quite some time for this to happen... But if you just had worked through the Unity learn section tutorials, you would know that this exact thing, like many other things are explained in existing video tutorials (hint).

    "and provide a script."

    Code begging isn't usually considered very polite.
     
    xVergilx and cohenburleson1 like this.
  3. cohenburleson1

    cohenburleson1

    Joined:
    Mar 11, 2019
    Posts:
    5
    Ik its not polite, I shouldn't be asking for scripts but sometimes you never know if someone would provide it. And i've looked through many tutorials, and haven't found any that shows how to pull back and release to shoot, especially in 3d. But if you're implying that there is a video on how to solve my issue, could you please be a friend and provide a link for me, or tell me which section of tutorials to watch? :) thanks
     
  4. olive157

    olive157

    Joined:
    Jun 4, 2013
    Posts:
    3
    Hey, sorry cohenburleson1, I cannot help you with your question, but I also would like some advice on this type of controls. I have been looking all over for a tutorial or an example project that could help me out. eses if you have seen a tutorial that could help us out here do you mind posting the link. I have looked through just about every related tutorial I could think of and I can't find it. Failing that, does anybody have any advise that could point me in the right direction to figuring this out myself. Cheers.
     
  5. eses

    eses

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

    Unity's Angry Birds tutorial explains the idea.

    But I haven't used such approach, I've just toyed with the concept and I used vectors instead.

    It is also easier to use raycasting against a plane defined by Plane class, or use raycasting against colliders so you can use any plane / surface you want.

    "Failing that, does anybody have any advise that could point me in the right direction to figuring this out myself."

    - Convert screen click to ray.
    - Raycast with this ray to a plane or ground.
    - Get the vector from object you want to move to raycast hit position.
    - Get the length / magnitude of this vector.
    - Add force to the moved object using inverse vector you now have and the magnitude of the vector.

    This way the object will be launched to opposite direction relative to pull.
     
  6. olive157

    olive157

    Joined:
    Jun 4, 2013
    Posts:
    3
    Hey @eses,

    Appreciate your reply. I will try and unpack that and see what I can get working. Thanks very much.
     
  7. cohenburleson1

    cohenburleson1

    Joined:
    Mar 11, 2019
    Posts:
    5
     
  8. cohenburleson1

    cohenburleson1

    Joined:
    Mar 11, 2019
    Posts:
    5
    go to his channel, pt 2 and 3 are on there
     
  9. GameforU

    GameforU

    Joined:
    Feb 8, 2019
    Posts:
    2
    Hello bro.
    I also searching about this but i do not find help from any where. If you find than please help me