Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by tommyzat · May 01, 2016 at 11:54 AM · movementpositionfloaty-axisy

Really confusing float question

Hello, I'm trying to have a OnTriggerEnter function, but I simply can't; My cilinder has a Y position of 0.625. Everytime it collides with the ground, it should make a sound, BUT it keeps changing from 0.625 to 0.625000001 back and forward really fast and I have no idea why. (also this is the only axis that keeps changing loads of times). This means it plays the sound everytime the 0.000001 is added.

Help?

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 jgodfrey · May 01, 2016 at 03:41 PM 1
Share

Your code shouldn't care about the difference between 0.625 and 0.625000001. The problem is not in that $$anonymous$$or variation, the problem is in how your code is dealing with it.

Post the code for further input.

avatar image tommyzat jgodfrey · May 01, 2016 at 04:24 PM 0
Share

@jgodfrey I'm posting a pastebin, the code is too long.

http://pastebin.com/erwGepX8

$$anonymous$$y ontrigger part is at the bottom, however maybe something from the rest may be relevant

avatar image tommyzat jgodfrey · May 01, 2016 at 04:31 PM 0
Share

Also do you know how I can stop the charactercontroller from always putting me 0.1 units above the air? $$anonymous$$y capsule is in 1 Y-unit in the air and the controller has the height 1.

1 Reply

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

Answer by Winterblood · May 02, 2016 at 12:24 AM

The physics has detected a collision with the ground, and because the ground is solid, it unembeds the capsule from it. Then on the next frame, the capsule falls under gravity again and collides with the ground. This is how the code makes you appear to "land" on solid surfaces.

You need to store some internal state so that you can tell the difference between standing on the floor, and landing on the floor after a fall. Luckily you already have it! Try this:

     void OnCollisionEnter(Collision collision)
     {
         if (!isgrounded && collision.gameObject.tag == "Ground")
         {
             audiosource.PlayOneShot(hitground);
             Debug.Log("xd");
         }
     }
Comment
Add comment · 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

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

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

Related Questions

How to make my float return to it's original value after being changed. 1 Answer

How to transform position to left? 1 Answer

How to move and position things to account for different resolutions? 0 Answers

There is a way to set a max to the resultant force in a object ? 1 Answer

How to constrain first person player to a path? 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