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 Aug 31, 2015 at 02:13 PM by Teddynieuws for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Teddynieuws · Aug 31, 2015 at 10:51 AM · animationcollidersraycastingfalling

Problem with raycasting from center of the collider

Hello,

I've got a problem with my game in unity.

I created a object with a box collider, and a player with a capsule collider. I created a function which returns wether the player is grounded or not using raycasting.

Now when the player is on top of the box collider it should show an idle animation. But this animation only shows up when the center of the collider is right above the box collider. When the collider's center is not above the box collider it will show a falling animation, but the player isn't falling because the collider is still colliding with the box collider.

Here's the code for the player:

 #pragma strict
 
 var speed : float;
 var jumpPower : float;
 
 var disttoground : float;
 
 var inair : boolean;
 
 
 function Start () {
 
 disttoground = GetComponent.<Collider>().bounds.extents.y;
 
 }
 
 function isGrounded() : boolean {
 
 return Physics.Raycast(transform.position, -Vector3.up,disttoground     );
 
 }
 
 function Update () {
 
 
 if(Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)){
 if(Input.GetKey(KeyCode.LeftShift)){
 
 transform.Translate(Vector3.right * speed * 3 * Time.deltaTime);
 GetComponent.<Animation>().CrossFade("Running");
 
 }else{
 
 transform.Translate(Vector3.right * speed * Time.deltaTime);
 GetComponent.<Animation>().CrossFade("Walking");
 
 
 }
 
 }else if(Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)){
 transform.Translate(Vector3.left * speed/2 * Time.deltaTime);
 }else{
 
 GetComponent.<Animation>().CrossFade("Idle");
 }
 
 
 //Jump code
 
 if(Input.GetKeyUp(KeyCode.Space) && isGrounded()){
 
 
 
 GetComponent.<Rigidbody>().AddForce(transform.up * jumpPower, ForceMode.Force);
 
 
 }
 
 if(! isGrounded()){
 GetComponent.<Animation>().Play("Jumping");
 
 }
 
 
 
 
 }


I hope you can help me :)

-Teddynieuws

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

Answer by Teddynieuws · Aug 31, 2015 at 02:13 PM

I managed to fix it by not using a raycast but a capsule cast.

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

28 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

Related Questions

Syncing a collider to a video 0 Answers

Implementing falling: How to maintain forward inertia as I transition into a fall animation? 0 Answers

Play other object's animation on camera trigger 0 Answers

How to have a collider stick to a certain part of a mesh? 0 Answers

Find a collision point from inside the object. 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