Search Unity

Raycast innacuracy

Discussion in 'Physics' started by Tornado77, Dec 19, 2018.

  1. Tornado77

    Tornado77

    Joined:
    Nov 14, 2018
    Posts:
    83
    Very simple question, how do i make raycast innacuracy ?
     
  2. What is Raycast inaccuracy?
     
    SparrowGS and hippocoder like this.
  3. Tornado77

    Tornado77

    Joined:
    Nov 14, 2018
    Posts:
    83
    I dont know if is possible but i am using raycast for my gun and i want to add innacuracy
     
  4. Add some random values when you choose your directional vector.
     
    xVergilx likes this.
  5. Tornado77

    Tornado77

    Joined:
    Nov 14, 2018
    Posts:
    83
  6. Tornado77

    Tornado77

    Joined:
    Nov 14, 2018
    Posts:
    83
    now i get Non-invocable member 'Vector3' cannot be used like a method.
    Code (CSharp):
    1. void SprayDirection()
    2.     {
    3.         var vx = (1 - 2 * Random.value) * shotSpread;
    4.         var vy = (1 - 2 * Random.value) * shotSpread;
    5.         var vz = 1.0;
    6.         return transform.TransformDirection(Vector3(vx, vy, vz));
    7.     }
     
  7. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    How about learning how to program in C# ?

    this means using the new keyword: new Vector3(vx, vy, vz)
     
  8. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Also you cant return Vector3(or anything else for that matter) on a void

    You should refer yourself to the learn section.
     
    hippocoder likes this.
  9. Tornado77

    Tornado77

    Joined:
    Nov 14, 2018
    Posts:
    83
  10. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    As I've said, you can't return anything on a void function, "void" says what the function returns, void is nothing, you want to replace the "void" with "Vector3" meaning that the function MUST return a Vector3.

    PLEASE, do yourself a favor and go study this stuff, you're jumping ahead of your knowledge and you gonna hit a major wall during development making you wanna quit because the game your dreaming about doesn't take form.

    https://unity3d.com/learn