Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Borzi · Jan 01, 2014 at 03:03 PM · vector3soundaudiosourcetimertime.deltatime

Problem with Footstep System

Hey! I am working on a footstep system with checks the ground via raycast to see on what kind of material the player is standing on and therefore creating the according footsteps. The problem is with the timer, because the "left foot" and "right foot" lines are logged very rapidly (and therefore creating a very weird sound) and in general when looking at the timer, it does not look like it is changing at all. Anybody know why this would be?

Here is a minimised version of my script I am using (it's long, but not very advanced):

 public bool isCreeping = false;
 
 public bool rightStep;
 public bool leftStep;
 
 public float stepTimer = 0.0f;
 [HideInInspector] public float checkRange = 15.0f;
 public float stepTime = 5;
         
 public Transform rightFoot;
 public Transform leftFoot;
     
 //Checks if the player is in air
 public bool grounded = false;
 
 void Update () 
     {
     //If the player is moving    
     if(Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0)
         {
         //If the player is not creeping
         if(isCreeping == false)
             {
             //Make foot steps
             CheckGround();
             }
         }
 }
 
 public void CheckGround ()
     {
         RaycastHit hit;
         Debug.DrawRay(transform.position, Vector3.down , Color.red);
         //Check for colliders below the player
         if(Physics.Raycast(transform.position, Vector3.down, out hit ))
             {
             Vector3 LeftFootPos = leftFoot.position;
             Vector3 RightFootPos = rightFoot.position;
             string floortag = hit.collider.tag;
             //Play sound for the according floor (in this case Terrainisch things like grass or mud)
             if(floortag == "mudFloor")
                 {
                 //If the timer is below "stepTime"
                 if(stepTimer < stepTime)
                     {
                     //Add to it over time
                     stepTimer += 1 * Time.deltaTime;
                     //If it is over or equal to stepTime...
                     if(stepTimer >= stepTime)
                     Debug.Log ("Produce Step Sound");
                         {
                         //..and the player is on the left foot
                         if(leftStep == true)
                             {
                             //reset the timer
                             stepTimer = 0.0f;
                             //play the sound at the left foot position
                             NetworkedSounds.Instance.Client_GrassFootStep(LeftFootPos);
                             //the player is gonna walk on the right foot next, so disable left foot...
                             leftStep = false;
                             //and enable right foot
                             rightStep = true;
                             Debug.Log ("Left Step");
                             }
                         if(rightStep == true)
                             {
                             //same thing with the right foot
                             stepTimer = 0.0f;
                             NetworkedSounds.Instance.Client_GrassFootStep(RightFootPos);
                             rightStep = false;
                             leftStep = true;
                             Debug.Log("Right Step");
                             }
                         }
                     }
                 }
             }    
     if(grounded == false)
         {
         //reset the timer if the player happense to be in the air
         stepTimer = stepTime;
         }
     }

 
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Borzi · Jan 01, 2014 at 09:10 PM 0
Share

Nobody got any ideas?

avatar image Griffo · Jan 02, 2014 at 03:05 PM 0
Share

If you'r using a Unity Terrain take a look at this

avatar image Borzi · Jan 02, 2014 at 07:26 PM 0
Share

That looks pretty interesting! But is unfortunately also not what I'm looking for at the moment.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by tanoshimi · Jan 02, 2014 at 04:49 PM

You intialise grounded as false, and never assign it any other value:

 public bool grounded = false;

Therefore this code block runs on every iteration of the Update() loop:

 if(grounded == false)
 {
 //reset the timer if the player happense to be in the air
 stepTimer = stepTime;
 }

Therefore your timer never changes.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Borzi · Jan 02, 2014 at 07:25 PM 0
Share

Well this is a snippit of the code and grounded does change (but this has to do with other code that I did not find relevant to include). Sorry for causing some confusion there.

avatar image tanoshimi · Jan 02, 2014 at 07:29 PM 0
Share

Well it's going to be hard to debug your code if you only paste some of it...

avatar image Borzi · Jan 02, 2014 at 10:12 PM 0
Share

This is the only code that is involved though...

avatar image Borzi · Jan 02, 2014 at 11:17 PM 0
Share

For some reason you were still right :D

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Audio Issue 1 Answer

Raycast and timer to select and lock-on to targets 1 Answer

Stealth AI Script. If less than or equal to not working correctly. Any fixes ? 1 Answer

How do I make the timeScale not affect the timer? 1 Answer

Best way to play many audio clips at the same time? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges