Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Imamul125 · Oct 08, 2018 at 12:28 AM · errorraycastingthird person controllerphysics.raycastisgrounded

can someone explain me this one line code

this code is about raycast.

 Physics.Raycast(transform.position, -Vector3.up * gravity, distToGround + 0.1f

as far i know raycast have starting point , direction and hit distance.. is disToGround + 0.1f hit distance.?? can anyone explain me in brief. Physics.Raycast(transform.position, -Vector3.up * gravity, distToGround + 0.1f

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 Eno-Khaon · Oct 08, 2018 at 01:21 AM

Well, first off, the example you provided isn't the entire function call.

That aside, as you said, the third argument is the distance; rather, it's the maximum length of the Raycast(). distToGround is a variable someone made for the call, so the intent with this particular Raycast() is to check from the character's position toward the ground (with a gravity modifier, presumably 1 or -1 in case gravity is reversed in the game's context), up to a maximum distance (distToGround) to determine whether the character is standing on the ground.

Edit: Furthermore, the + 0.1f is there for padding. If you have a capsule collider character with a center 1 unit from the ground, then fire a Raycast, a 1.0-length Raycast has a chance of unexpectedly falling short due to rounding errors, whereas 1.1-length, after adding the padding, ensures it will hit the ground more reliably.

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 Imamul125 · Oct 08, 2018 at 06:22 PM 0
Share

thanks a lot. @$$anonymous$$o-$$anonymous$$haon but i dont know what's wrong in my code still i am not able to get desire answer. i have animation of landing and i want animation to get triggered as soon as my character reach certain height. but nothings happens. ins$$anonymous$$d my character jump at height and then get stuck mid air and the stuck pose moves mid air by "vertical" and "horizontal" keys. is something wrong with this code. i know it is just the snippet of the code. if you need i can post the full code. void jumpDown() { if (Physics.Raycast(transform.position, Vector3.down, height)) { anim.SetBool("jumpDown", true); } else { anim.SetBool("jumpDown", false); } }

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

126 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

Related Questions

NullReferenceException Error 0 Answers

Javascript and start Assets not available 1 Answer

Property 'UnityEditor.Editor.preview' is read only. 1 Answer

Same code in 2 different scripts with different outcomes 0 Answers

Unity 2017.3.0f3 Gradle Build Error 2 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