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 cvbattum · Oct 06, 2015 at 11:58 AM · collisionphysicsraycast

Physics.Raycast() always returns false

I have already looked for solutions to this problem online, but none of them seem to solve my problem. To make a chracter controller, I followed this tutorial. This is the second part in a longer series. The first part worked perfectly for me. The second part however, when finished made me unble to move. The problem is that my code thinks I'm never on the ground, and thus my velocity vector is constantly decreasing on the y-axis (falling).

My code:

 private bool Grounded() {
     return Physics.Raycast(transform.position, Vector3.down, moveSettings.distToGrounded, moveSettings.ground);
 }
 
 private void Jump() {
     Debug.Log(Grounded());
     if (jumpInput > 0 && Grounded()) {
         //Jump
         velocity.y = moveSettings.jumpVel;
     }
     else if (jumpInput == 0 && Grounded()) {
         //Grounded
         velocity.y = 0;
     }
     else {
         //Falling
         velocity.y -= physicSettings.downAccel;
     }
 }

I don't think it's a problem with the code, as it is exactly identical to what is used in the tutorial. The player object is a simple, standard cube with a standard box collider, straight from the add menu. What's basically happening, is that I'm unable to move because the y of my velocity is increasing way too much. This happens because the Grounded() method, basically a substitute for Physics.Raycast, always returns false.

I'm really out of ideas on how to fix this, that's why I'm here.

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

Answer by Oribow · Oct 07, 2015 at 05:03 PM

The last argument in Physics.Raycast defines the layers that the raycast will hit. That could be the problem, if the layer of your ground isn't specified here. When you leave this argument out, no layer gots ignored, so try that. Another problem could be that moveSettings.distToGrounded is to small and it is just inside of the playermodel.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

how to prevent a kinematic rigidbody from going through static colliders 0 Answers

How to raycast object as far as possible, without collision? 0 Answers

Raycast collision vs unity collision system ( 2D Android game). 1 Answer

RayCast not working , why ??? 0 Answers

Sphere bouncing back on edges of aligned objects 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