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 /
This question was closed Jan 18, 2015 at 11:49 AM by Entyro for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by Entyro · Jan 05, 2015 at 12:43 PM · footsteps

Player Footsteps in stairs Problem

Hi!

I have a problem with my footsteps script when I walk down some stairs ingame. Just watch the video below to see what happens.

Video: https://www.youtube.com/watch?v=fHtyNNV0ELA

Does anyone know why it's like that?

Footstep script:

 public var walkSounds : AudioClip[];
 public var runSounds : AudioClip[];
  
 public var walkAudioSpeed : float = 0.4;
 public var runAudioSpeed : float = 0.2;
  
 private var walkAudioTimer : float = 0.0;
 private var runAudioTimer : float = 0.0;
  
 var isWalking : boolean = false;
 var isRunning : boolean = false;
  
 public var walkSpeed : float = 8;
 public var runSpeed : float = 20;
  
 public var sprintDuration : float = 10.0;
 private var sprintTimer : float = 0;
 private var stamina : float = 0.0;
 var CamAnimationScript : CamAnimation; 
 //public var staminaTexture : Texture;
  
 private var chCtrl: CharacterController;
 private var chMotor: CharacterMotor;
 public var flashlightAnimation : GameObject;
 
  
 function Start()
 {
     chCtrl = GetComponent(CharacterController);
     chMotor = GetComponent(CharacterMotor);
 }
  
 function Update()
 {
     SetSpeed();
  
     if ( chCtrl.isGrounded )
     {
        PlayFootsteps();
     }
     else
     {
        walkAudioTimer = 1000.0;
        runAudioTimer = 1000.0;
     }
 }
  
 function SetSpeed()
 {
     var speed = walkSpeed;
  
     if ( Input.GetAxis( "Horizontal" ) || Input.GetAxis( "Vertical" ))
     {
        if ( Input.GetKey( "left shift" ) || Input.GetKey( "right shift" ) )
        {
 // Running
          isWalking = false;
          isRunning = true;
          CamAnimationScript.running = true;
          CamAnimationScript.walking = false;
        }
        else
        {
 // Walking
          isWalking = true;
          isRunning = false;
          flashlightAnimation.animation.CrossFade ("Flashlight", 0.2);
          CamAnimationScript.running = false;
          CamAnimationScript.walking = true;
        }
     }
     else
     {
 // Stopped
        isWalking = false;
        isRunning = false;
        flashlightAnimation.animation.CrossFade ("Flashlight", 0.2);
     }
  
 // check the sprint timer
     if ( isRunning )
     {
        sprintTimer += Time.deltaTime;
  
        if ( sprintTimer > sprintDuration )
        {
          isRunning = false;
          isWalking = true;
          CamAnimationScript.running = false;
          CamAnimationScript.walking = true;
        }
        else if ( chCtrl.isGrounded )
        {
          speed = runSpeed;
        }
     }
     else
     {
        sprintTimer -= Time.deltaTime;
     }
  
     sprintTimer = Mathf.Clamp( sprintTimer, 0, sprintDuration );
  
     chMotor.movement.maxForwardSpeed = speed;
  
     stamina = 1.0 - ( sprintTimer / sprintDuration );
 }
  
 function PlayFootsteps()
 {
 // Play Audio
     if ( isWalking )
     {
        if ( walkAudioTimer > walkAudioSpeed )
        {
          audio.Stop();
          audio.clip = walkSounds[ Random.Range( 0, walkSounds.Length ) ];
          audio.Play();
          walkAudioTimer = 0.0;
          flashlightAnimation.animation.CrossFade ("Flashlight", 0.2);
        }
     }
     else if ( isRunning )
     {
        if ( runAudioTimer > runAudioSpeed )
        {
          audio.Stop();
          audio.clip = runSounds[ Random.Range( 0, runSounds.Length ) ];
          audio.Play();
          runAudioTimer = 0.0;
          flashlightAnimation.animation.CrossFade ("FlashlightSprint", 0.2);
        }
     }
     else
     {
        audio.Stop();
     }
  
 // increment timers
     walkAudioTimer += Time.deltaTime;
     runAudioTimer += Time.deltaTime;
 }
  
 //function OnGUI()
 //{
 //    if ( staminaTexture ) // check there is a texture so it doesn't error if not
 //    {
 //        GUI.BeginGroup(new Rect(30, Screen.height - 50, 405 * stamina, 25));
 //        GUI.DrawTexture(new Rect(0, 0, 405, 25), staminaTexture);
 //        GUI.depth = 0;
 //        GUI.EndGroup();
 //    }
 //}



Comment
Add comment · Show 4
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 CodeElemental · Jan 05, 2015 at 12:55 PM 0
Share

The youtube video is private :\

avatar image AlucardJay · Jan 05, 2015 at 12:57 PM 0
Share

video link is private for me. At a guess, the character controller is returning isGrounded as false, and the character controller is actually sliding down the stairs. This is where its happening :

 if ( chCtrl.isGrounded )
 {
     PlayFootsteps();
 }
 else ....

I don't have an immediate solution rather than to :

see if changing the Slope Angle variable on the character controller helps detect grounded on stairs (are you using the legacy or the sample assets beta controller?)

do your own isGrounded raycast check : if when the character controller finds the slopeAngle too large; of if the rayhits a specific tagged collider.

http://answers.unity3d.com/questions/596645/limited-sprint.html

avatar image Entyro · Jan 05, 2015 at 01:04 PM 0
Share

Now the video works!

avatar image Entyro · Jan 05, 2015 at 04:10 PM 0
Share

No difference when I change the slope angle. I'm using the Standard Assets controller

1 Reply

  • Sort: 
avatar image
0

Answer by hexagonius · Jan 05, 2015 at 05:47 PM

I guess you're using the Move function of the Character Controller. You're slope is very steep. I would say the problem is, that for the downward movement, the default gravity is just not enough to keep you constantly on the floor. You're kind of micro hopping down the stairs. You should check for stairs via code and try either increasing the gravity during that time (I did that), or you adjust the move direction to match the slope of the stairs so you're controller moves parallel. To check if the hopping is the case create your own bool variable, make it public and set it every frame to the isGrounded value of the controller. You should see it flickering in the inspector while moving down.

Comment
Add comment · Show 1 · 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 Entyro · Jan 06, 2015 at 01:47 PM 0
Share

I don't get any other result by changing the gravity

Follow this Question

Answers Answers and Comments

27 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Toggle map/Camera [JS] 1 Answer

Problem with my car enter/exit script 1 Answer

C# scriping help 0 Answers

supplied parameters doesn't match the rpc declaration 1 Answer


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