Search Unity

Shooting in Unity, Raycast or Gameobjects?

Discussion in 'Physics' started by DasJonny, Jun 20, 2017.

  1. DasJonny

    DasJonny

    Joined:
    May 15, 2017
    Posts:
    32
    Hello!
    I am quite new to programming at all, and so far i am making a little Shooter based on Brackeys Multiplayer FPS Tutorial on Youtube.
    For shooting, he is using the Raycast, as it is - as far as i saw - quite usual.
    Now I am wondering, if an alternative to raycast would be simply creating GameObjects, such as bullets, spawning at the player and getting a force towards the direction the player looks at.

    I think it would be a cool way for possible power-ups, like creating a slow-mo field where bullets are very slow, etc.

    Is there a reason, most shots are made through raycast instead of the way i just told?
     
  2. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    Yes there is a reason. I do both though I create a bullet / projectile for a visual effect, and then and I have a script on the projectile do the raycast. The reason raycast is done is because projectiles can move so fast in a game that between frames they can skip over the point they were supposed to collide with. You can mess with the collision detection type on colliders but that can give mixed results where as the raycast technique seems fool proof.
     
    DasJonny likes this.