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.

Question Audio with Visual Scripting (Newbie Question, Help Greatly Appreciated)

Discussion in 'Visual Scripting' started by WindReiter, Sep 30, 2022.

  1. WindReiter

    WindReiter

    Joined:
    Jul 29, 2022
    Posts:
    7
    Hi there everyone.
    Apologies if this has been covered before, but I can't seem to find answers particularly relevant to what I'm trying to figure out.

    Are there any good resources that the community knows of for learning how to program 3D game audio using visual scripting?
    We're just starting the process, and others on the team want to use Visual Scripting rather than C# as a base for creating the game functionality.

    For example, I want to create footstep sounds for my first person character that are responsive to changes in terrain. However, all of the resources on this I can find through searching lead to solutions that are C# script-based.

    Is there anyone on here that has experience implementing this kind of application to Visual Scripting? If so, do you have any advice as to where a newbie like me should go to best learn about how to do this?

    Apologies for the lack of knowledge. Honest and deep thanks for the help!!
     
  2. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    Hey, asking is a good way to learn stuff.

    How you find the ground type will depend on the kind of character controller you're using and how you have set up your scene. For example, if your ground types are separate blocks or colliders, you could do a collision check or raycast towards the ground each step to return the thing you're standing on.

    You could use tags or layers, names of the blocks all kinds of stuff. that's why it matters how you set up your game. dictates how to fetch it.

    Once you know the type of ground you're currently standing on, all you've really got to do is switch what sound is played through the Audo Source Component. And separately you would have some kind of timer to control the footstep intervals so that the sounds match your speed and such.


    Capture.PNG
     
    WindReiter likes this.
  3. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    355
    While this isn't particularly technical what I've done here, maybe give some ideas on making footsteps on an audio source.
     
  4. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    355
  5. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    beauty, all's you gotta do is experiment and it'll become second nature! good stuff.
    on that note i've gone ahead and thrown together a demo of how one could accomplish this task using the character controller component base, looking for 3d colliders to stand on.

    The idea with this was to make it as obvious or easy to see as I could. everything about this could and should be changed or updated as a game evolves but this is how I went about doing what I did below. (bare with me as there's a cap on how many images I may attach to a single post.

    Here is a video of the end result as a reference




    Here is the start of the entire project. A group with comments (editable in the graph inspector).
    I'm just outlining all of the features I want to add to this walking thing while keeping the ideas open ended.
    Nested inside the group is a Subgraph Node that gives my Character Controller the ability to Move. just added an exterior speed value to make it more obvious what the node does.
    goal.PNG



    This is the code Nested within the Subgraph. Super easy way to make the Character Controller Move. But can't Jump. (use Move for that lol) I would not use this as final movement code. only a placeholder. pro tip, leave place holder code all messy, and tidy up good code.
    0_ezmove.PNG

    Here is an overview of the completed graph as shown in the video above. Note that you can have multiple updates on the same graph to make things easy to see before going back and streamlining. Can see how each segment is divided into jobs or functions that closely resemble the Goal comments.
    0-overview.PNG

    Here's how I got the Hierarchy set up. Character Controller is the object that's got the Graph on it and each kind of ground tile is tagged with the appropriate tag to distinguish it.
    0_hi.PNG 0_tag.PNG
     
    Last edited: Oct 1, 2022
    WindReiter likes this.
  6. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    Here is what my variables look like. All this would change if I decided to get the material name or something else to decide what ground I'm touching. Here I'm using collisions and tags.

    Is moving, is a bool that is True when my character controller is in motion either by momentum or continuous input from a keypress and False when it's velocityis below a threshold, or dead-zone.
    0_vars.PNG
    1-detectmove.PNG
    2-ray.PNG 3-vol.PNG 4-steps.PNG
     
  7. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
  8. WindReiter

    WindReiter

    Joined:
    Jul 29, 2022
    Posts:
    7
    Hey REDACT3D_, thank you so much for your detailed help! This is an awesome welcome into the Unity community =D. My sincere apologies as I haven't realized that there's been a reply to my initial question until now.
    I will dive into this and try it out for myself!

    I ended up caving and creating a solution using C# scripting for now, which actually worked quite nicely.
    However, I still think learning how to implement a solution using visual scripting as you've so kindly described would be helpful to be able to more easily communicate my logic with other designers and 3d modelers whom I'm collaborating with.

    Thanks so much again for taking the time to directly reply! I'm excited to jump in and try to implement a solution this way.
     
  9. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    You're welcome, bud

    Glad you found a solution that works for you. It would be interesting to take that C# Script and convert it to a graph and try to replicate the same end result.

    And welcome to the forum!
     
    Skaravic likes this.