- Home /
Footsteps on different terrain idea
I have a idea, im at college right now so cant get access to unity. Been on a roll with programming recently. If i make a extra variable in this code then a if statement that basically if a gameobject is hit then it changes the sound to the new variable? I will try it out later :) then i can add a new variable for all teh curface types and just add a plane onto the surface with mesh render off.. hmmm
var footsteps : AudioClip;
//INSERT NEW VARIABLE VAR MUD :Audioclip;
function Start()
{
audio.clip = footsteps;
audio.loop = true;
}
// function start_2 ()
{
audio.clip = mud;
audio.loop = true;
}
function Update()
{
if (Input.GetKeyDown (KeyCode.W))
audio.Play();
else if(Input.GetKeyUp (KeyCode.W))
audio.Stop();
}
I already see errors but what you guys think :) ill work on some pseudocode tonight
Answer by Z2CSharp · Apr 25, 2013 at 01:43 AM
If you want to be able to detect what you are walking on you would definitely need a raycasthit and tags on your gameObjects to trigger the right audio
private RaycastHit hit; // What terrain we hit
public Transform Character_T; // The transform (Position) of our character
private float Speed = 1.0f; // How fast the character moves
void Update()
{
transform.Translate (0,0,Speed * Time.deltaTime);
if(Physics.Raycast(Character_T.position,-Vector3.up,out hit,100.0f)) // Send out a ray from character position down at 100.0f, if java, forget the out modifier
{
print ("I be firing my ray");
}
if(hit.collider.tag == "Mud_Terrain" && Speed >= .1f) // If we are walking on mud terrain
{
audio.Play(); // Play the mud terrain audio
}
}
I didn't define a mud audio in the script though :(
nice idea, obviously you would need to incorporate the if w is pressed part in there. I have actually got it working by a variety of different ways. just wanted to know if anyone else did what i said
Your answer
Follow this Question
Related Questions
FPS footsteps only work when jumping/hitting edges of a mesh 1 Answer
Random Footsteps with variable pitch and volume 1 Answer
How can I create headbobbing with footstep sounds and running? 1 Answer
Footstep Script (NullReferenceException: Object reference not set to an instance of an object) 1 Answer