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
1
Question by ToxicNova · Apr 10, 2015 at 05:02 PM · javascriptcharactercontrollerunity 4.6movingsounds

How to test if a charactor is walking on terrain (to make a walking noise)

Hello, so I have this walking clip that I wanted to add to the charactor motor script to make it play a sound every time I moved. When i did that, it played that sound if I was moving in the air, jumping, or just standing still (as well as walking). What would be the best way to play this sound when I'm just moving on the ground.

Also, I don't want a testfor W,A,S,D becuase it would still play that sound when I'm in the air and holding those buttons down. (Java scipt would be appreciated since I'm still new and trying to get used to unity)

Thanks in advance!

Comment
Add comment
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

1 Reply

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

Answer by DoTA_KAMIKADzE · Apr 10, 2015 at 05:25 PM

You can use Linecast or Overlap or Raycast to detect a collision with the objects below the character and detect if it is a ground or not.

Here I've found an example with Raycast for you.

Then simply add boolean parameters or int parameter in your animator to transfer from your one of your state to another.

And finally add code for animating if you are on the ground. Here is an example code for boolean if it was called "Walk":

 public class PlayerScript : MonoBehaviour
 {
     private Animator _anim;
     [SerializeField]
     private string walkAnimation = "Walk";
     private bool grounded = true;
     internal bool isWalking
     {
         get { return _anim.GetBool(walkAnimation); }
         set { _anim.SetBool(walkAnimation, value); }
     }
     private void Awake()
     {
         _anim = GetComponent<Animator>();
     }
     private void Update()
     {
         //blablabla
         isWalking = grounded;//walking if on ground
         //blablabla
     }
 }

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 ToxicNova · Apr 11, 2015 at 08:46 PM 0
Share

Thanks, that helped me a lot.

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

19 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

Related Questions

Enemy moving sideways 1 Answer

Changing the light color with sliders 1 Answer

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Collision Detection 0 Answers

Using acceleratorometer, manipulate the data to trick phone into thinking gravity is pointing in a different direction than down. 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