Anyone have any idea how you would set up footstep sound in VR. All the tutorials I’ve seen use the walking animation in the player character but in vr you don’t use animation for the main player vr pawn.
Which template you use it for VR?
Weapon master vr from the marketplace.
One way to do it would be to keep track of the distance the pawn has moved and produce a step sound every 50 cm or so. To make it more realistic, you should also consider the speed (higher speed = higher stride distance) and the physics / material of the terrain under the pawn.
Any idea of how I could keep track of the distance traveled?
Create two variables, Last Position as Vector and Distance as Float. On Pawn movement (or Event Tick), calculate GetActorLocation - Last Position. The length of this vector is the moved distance. Add it to Distance and check whether Distance > Stride Length. If so, make a foot step sound and subtract Stride Length from Distance, so you are ready for the next step. Of course this only makes sense with Thumbstick locomotion, not with teleportation.
I have been busy for the last few weeks so I only saw your reply now. I haven’t tried this yet but I will tonight. Any idea how I could have different sounding footsteps. One for grass one for wood and so on. I know how to set up the materials for different sounds but again that only works when an object physically touches the material not for a vr pawn. Someone said setting up a line trace but how would you get that to work with your bp?
In an Event Tick, you can use Line Trace By Channel to trace down (negative Z direction) from the center of your Pawn to the underlying terrain. By breaking Hit Results, you will see there is a Phys Mat property. From that one you get Surface Type and then Switch among the different types of physical surfaces to make different sounds. It doesn’t matter that the Pawn doesn’t have a physical body because you use raycasting to “sample” the underlying material and get its physical surface type.
Perfect thanks I’ll try that when I get home.
Hi I am trying to put together this BP but now that I am trying I’m finding there are a few missing pieces or misunderstanding on my part. OK so I have created the two variables. Last position as a Vector and distance as a float.
Pawn movement would be a bit tricky with the pawn I’m using so I’ll go with event tick. Now you say to “calculate the getactorlocation node - last position” but what do you mean by calculate?
The Last Position vector doesn’t connect to the get actor location node so there must be another node that you didn’t mention that allows me to do that. To “Calculate” it. I don’t know what node to use so that is where the gap in my knowledge comes in.
Now I think I know what you mean by “The length of this vector is the moved distance. Add it to Distance and check whether Distance > Stride Length. If so, make a foot step sound” which are these nodes.
But when you mention “and subtract Stride Length from Distance, so you are ready for the next step.” again I’m not sure what nodes I would use here and where to plug them in.
Lastly I think I have got the Line Trace By Channel for different footstep sounds right but I can’t check until I figure out that 1st part and what you want me to do with the getactorlocation node.
I meant calculate the vector difference between GetActorLocation and Last Position (there was a minus sign in between them in my original message but could have easily been missed)
The Length of this difference vector is the moved distance
Hi I’m sorry I don’t think I explained ,myself properly. You only mention 4 nodes. The event tick, a vector which is called Last Position, a float which is called Distance and getactorlocation. I don’t know what node to plug the getactorlocation into. How do I connect the GetActorLocation node and Last Position vector. Using vector difference? Which node is this? How do I connect the getactorlocation node to the event tick. There must be other nodes I have to use that you are not mentioning? Here is a picture to better explain what I mean.
You have to subtract the two vectors, so the node it use is Vector - Vector.
Then you take the length of the difference vector above and add it to the curent Distance (with a Set). In pseudo-code:
Distance := Distance + Length(GetActorLocation() - LastPosition)
Then you check if Distance > StepDistance and if true you make a step sound. After making the step sound you do
Distance := Distance - StepDistance
so you are ready for the next step.
OK I think I’m close but I’ll need your help answer a few questions and if you can answer each one I think I should get it then.
(1) When you say “You have to subtract the two vectors, so the node it use is Vector - Vector.” Do you mean this?
Yes or no?
(2) When you say “Then you take the length of the difference vector above and add it to the curent Distance (with a Set).” Do you mean this?
If you didn’t mean to set the distance float then can you tell me exactly what you mean by current distance (with a set) how do I know what the current distance is?
(3) When you say “Then you check if Distance > StepDistance and if true you make a step sound.” Do you mean this?
(4) What does this “:=” mean?
Good, you are almost there!
(2) no, you have to add the Length of the difference vector to Distance and assign (Set) the total to Distance. Basically you keep adding the magnitude of the last movement to Distance until (3) is true.
(3) no, you have to compare Distance with StepDistance, not with itself. StepDistance is a new float var you set to, say, 50 (meaning one step sound every 50 cm of movement). And between Set Distance and the Branch, you need to assign (set) Get Actor Location to Last Position so you are ready for the next frame. Remember you are working into an Event Tick.
(4) After you have produced the step sound, you have to assign (Distance - StepDistance) to Distance. The symbol := means assign to or, in UE4 terminology, Set. This is needed to reset the Distance variable and restart adding to it until the next step occurs.
In case you are still struggling with it, here is the full solution which works in the FPS template (also in VR mode). It has a couple of improvements respect to what I described above:
- An initial check prevents a stray step sound as soon as the game plays
- Alternate sounds for left and right foot
Step Distance is set to 125.0 which seems to work well with the gun animation also out of VR mode, but you can play with that value and see what feels good to you. Have fun!
Thats perfect. Thanks
@tcla75 you are welcome!
Even made an improved tutorial for you here
Wow thats amazing thats going to help a lot of people Marco and just to add a screen based on what you said if anyone wants to have different sound steps for wood grass carpet and so on just add the following code on the end of Marco’s bp The default footstep sound below is a variable I added. In the variable type search for sound base then put your default footstep in there. It will ensure if you walk over a material that doesn’t have a phys material assigned to it a regular step will still play.
Well done! Thanks for sharing back with the community.