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. Dismiss Notice

How do I make a cannon that shoots a prefab in random directions

Discussion in '2D' started by Lil_Potatoe, Apr 25, 2021.

  1. Lil_Potatoe

    Lil_Potatoe

    Joined:
    Feb 2, 2021
    Posts:
    16
    Hey, so I want to make a cannon in my game that will spawn and shoot a prefab in a random direction (kinda like bullet spread). My problem is that I don't really know how to spawn a prefab in a game object, then launch it in a random direction with a random launch force. Thank You for any help.
     
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    There are many tutorials out there on this topic and this has probably been answered quite a few times.
    So, did you do any searches? Just go to Youtube or google "Unity shooting tutorial" and you will get many hits, like this one by Code Monkey.

     
  3. Lil_Potatoe

    Lil_Potatoe

    Joined:
    Feb 2, 2021
    Posts:
    16
    Yes, I've been through quite a lot of youtube videos and other unity forums but I haven't been able to find what I've been looking for. I want to know how I can spawn and then immediately add a random force that will launch it out of the cannon, kinda like a slingshot but without pulling it back. I don't want it to be like a weapon that will shoot a bullet where you have aimed it too and at the same velocity every time.