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 /
avatar image
0
Question by unity_E27TflsXdrCJfA · Dec 07, 2017 at 02:54 PM · collisionjumpjumping

Dynamic collider when jumping.

I have this jump animation that "crouches" the model when jumping. Now, this makes the feet deceptive, because if the feet would appear to land just on top of a ledge, the collider box would hit the side of said ledge by a large margin.

This is my solution to the problem:

     coll = GetComponent<CapsuleCollider>();
     if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
     {
         coll.center = new Vector3(0.0f, 1.4f, 0.0f);
         coll.height = 1.5f;
         isGrounded = false;
         rb.AddForce(new Vector3(0.0f, jumpHeight, 0.0f));
         anim.SetTrigger("isJumping");
     }
     void OnCollisionEnter()
     {
         isGrounded = true;
         coll.center = new Vector3(0.0f, 0.86f, 0.0f);
         coll.height = 1.9f;
     }

(Both the input part and getcomponent are both in their corresponding functions, and "coll" is defined above, I just set it up like this for relevancy. This does "work")

Now, the issue here is apparent. When jumping, the collider becomes smaller, which means that when the character model lands, the collider is far above its feet, causing the character to sink into the floor before the collider is reset. The question is if there is an alternate solution to this, a fix, or if I just have to add another hitbox (which is just plan B, I wouldn't want this if there is another way.)


as a sidenote, I'm trying to integrate double jump into my existing functions, so if it's not too much trouble, I'd appreciate it if you could include that in the answer

Comment
Add comment · Show 1
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 NorthStar79 · Dec 07, 2017 at 03:01 PM 0
Share

You can just use RayCast for detecting ground below for expanding collider before landing, something like this :

 private void Update() {
                  if(!isGrounded && Physics.Raycast(new Ray(playerFeetPositionVector,Vector3.down),DistanceForFeetControl))
                  {
                      isGrounded = true;
                      coll.center = new Vector3(0.0f, 0.86f, 0.0f);
                      coll.height = 1.9f;
                  }
              }


please note that this is just pseudo code

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by ASPePeX · Dec 07, 2017 at 03:14 PM

The "nice" way of doing it would be to fix the animation so the transform origin is always the the characters feet.

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

118 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

Related Questions

Player sticks to ground occasionally after trying to jump 0 Answers

Jumping on top of an enemy problem 1 Answer

Can't figure out how to detect ground (2D) 1 Answer

Box collider didn't jump with player 1 Answer

Detecting Collision for Jumping 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