• 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 minor 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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 properly make an object follow the edge of another object? 0 Answers

Character Will Not Move from Spot (At All) 0 Answers

How to constrain first person player to a path? 0 Answers

How can I check if a player is moving positive or negative on the y axis? 0 Answers

Limit object y position 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges