Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by adriandevera · Jun 06, 2015 at 05:29 AM · animationraycastdetectiongroundfall

Error in Raycast Detect Ground for Falling Animation

Ive been working on a controller for my game for a couple days now and its been going very smoothly however I ran into this small bug where the fall animation would play when a Ray Cast is determind but the character's Capsule Collider (radius of 0.3) still collides with the wall edge and therefore the model stays on the edge but plays this falling animation.

I have the image here to best explain what goings on: http://gyazo.com/e34f79cfe762f930921ee22f3182cb2e

I know the issue here is that I only have one ray cast that is very slim and since the radius of the character is 0.3 theres a small slight error in which the raycast would not hit the ground thus thinking it should play the animation but the collider still does.

Heres the code:

  //grounding checks
 bool grounded = true;
 public bool Grounded { get { return grounded; } }
 private RaycastHit groundHit;
 public float groundedDistance = 1.5f; // from capsule center
 public LayerMask groundLayers = -1;
 private float groundheight = 0.0f;

void Update () {

     //check if grounded
     grounded = Physics.Raycast (unit.position + unit.up * capcolllider.center.y, unit.up * -1, out groundHit, groundedDistance, groundLayers);
     anim.SetBool ("grounded", grounded);

Here is the setup: http://gyazo.com/3d35abc0038370a5e1012d996d06f113

Also I have 3 fall Landing animations that I would like to play when the character hits the ground at particular heights. As of right now I just have one playing but I would like to play the others depending on the height of the fall. If the fall is 0-3 unit meters then play LandA, if 3-10m then play LandB and then greater than that then LandC (which is basically a death falling animation).

I know to achieve this I just need to measure the distance of the Raycast itself but Im not quite sure how, still a little new to raycast functions

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
0
Best Answer

Answer by Aggrojag · Jun 06, 2015 at 06:46 AM

An easy fix would be to simply have the wall on a different layermask. With the collider that small you're kind of asking for these types of problems. If a separate layermask if out of the question, perhaps you could also check the tag or name of the hit object.

For measuring distance, I believe RaycastHit.point will get you started. http://docs.unity3d.com/ScriptReference/RaycastHit-point.html

Hopefully this helps. Best of luck.

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 adriandevera · Jun 06, 2015 at 12:48 PM 0
Share

Alright ill check out that RaycastHit.point

As for the layermask and tag, the reason I am not putting the wall on a seperate mask as the ground is because this was just a test scene where I plan to have floating platforms and the ground is just about nonexistent.

I cant remember but since im using a capsule collider, how would I make it so that the bottom rounded ends are slippery when at an edge? I remember making a system back in Unity 4 but I cant remember my thought process and no code was needed. Perhaps a setting for the capsule collider?

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

RayCast Boolean Help 1 Answer

Detect Falling 3 Answers

Raycast problem trough the terrain 1 Answer

detection raycast too late 2 Answers

i have 2 assets , i want to make a text appear after a collision between them (and end the game if that is possible) , how can i do that ? 1 Answer


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