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 /
This question was closed May 16, 2017 at 09:34 PM by Gabestronaut for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Gabestronaut · May 16, 2017 at 05:59 AM · movementraycasttransformcharactercontrollervector3.distance

Vector3.Distance returning offset values due to down force interference.

Essentially this is what I am doing 1.Casting a Ray down to the ground from player. 2.float distance = Vector3.Distance(transform.position, hit.point);

When it executes, before I input anything the values seem reasonable. Once I input movement the values vary sporadically up to 9.0 when it shouldnt exceed more than 2 at most. I have encountered the problem but have no solution. Essentially the character controller down force is interfering with the Distance values because there is a verticalVelocity += downforce value; or to be more specific movement.y -= speed.

Before you say, duh make sure your player is grounded and dont add force when it is. THAT was one problem to begin with. The character controller isGrounded check returns true/false several times per second if there is now downforce thus immediately causing problems with jump if you try jumping while isGrounded = true. To add to this pain, if youre on a slope and moving down, the character controller bounces downward causing even more sporadic checks of the is grounded bool. So I have fixed all of these pains by default by adding constant forces to Y value to ensure I am grounded at ALL times when my feet are planted. By default, try it, Debug.Log a character controller's isGrounded (CharacterController.isGrounded) bool without force. It will consistently return true and false. I cant seem to find a solution because at no point can I turn those forces off or my controller will not be responsive. All is grounded check return perfectly fine as is with constant forces. I also print(myposition + hit.point) and they both are the expected static values even while I move. So why cant vector3.Distance keep track of that???? Anyways I will post my code and hopefully someone will have luck.

Lastly you may ask, why do I need this, 90% of the controller is functional, especially for what I specifically need. Slopes work fine say up to 80 degrees. After that, I have several issues where too steep is too much and the raycast doesnt pick up the floor and I can climb steep slopes with no sliding. So i want to check that raycast distance. If the control isGrounded and the distance is great, then I am floating on a steep slope and I use the OnControllerColliderHit to solve that. By default OnControllerColloderHit is terrible with smaller slopes, but with steep it work great so I want to use a combination of the two. Thank you.

FirstPersonMoveScript

movement.txt (9.2 kB)
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

  • Sort: 
avatar image
0

Answer by Gabestronaut · May 16, 2017 at 09:34 PM

UPDATE: It turns the weird number fluctuations were epsilon values. In order to solve the numbers:

float distance = Mathf.Round(hit.distance * 100) / 100; Debug.Log(distance);

So I was getting the right distance, but it was just giving me Epsilon Values or the precision float closes to 0 but not 0. So that was throwing me off big time. I was expecting something close to 0 or 0. NOT

9.########e##

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

Follow this Question

Answers Answers and Comments

164 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 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 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

i am using a code to make my cube walk with character controller ,but when i play the cube spins. 0 Answers

Character Controller Move function Explanation 0 Answers

i'm using a code to make my cube walk with character controller but when i play the cube spins. 0 Answers

Using Velocity breaks my jumping 0 Answers

I'm almost finished with my game, but I have a major bug that makes it basically unplayable, can someone help please 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