Search Unity

How to get the area of a mesh with a raycast and using it as a variable?

Discussion in 'Scripting' started by JackQuinton, May 24, 2017.

  1. JackQuinton

    JackQuinton

    Joined:
    May 2, 2017
    Posts:
    2
    In more detail I'm a sound designer and I have a metal hit sound that plays when a raycast'd 'bullet' hits anything with a 'metal' tag.

    It sounds good with some smaller metal objects but the sound is too high pitch for the larger ones. I can set a parameter in FMOD to lower pitch based on a variable (e.g the area of the box mesh on the object)

    How do I get the raycast to check the area of the mesh it hits as well as the tag so I can set my fmod parameter to it and trigger the fmod event.
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Can you get away with cheating and using the bounds of the Mesh instead of the area? It sounds like it will be close enough for your task.

    Working out the actual surface area will require you to grab every triangle in the Mesh and calculate its area. Simple enough to do, but probably more performance intensive then makes sense.
     
    JackQuinton likes this.
  3. JackQuinton

    JackQuinton

    Joined:
    May 2, 2017
    Posts:
    2
    Yes that sound a liable option. I'm very basic to scripting in unity as I'm primarily a sound designer reaching out. I basically just need a way to get a variable from the raycast that can contrary the objects size.
     
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860