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 MadsDTU · Oct 22, 2018 at 01:55 PM · colliderplayercollider2dtilemapcollider 2d

Collider problems?

Hey Unity Forum.

I have this issue with my game where my avatar kinda falls down into the tile object when i jump around for a short time. I am not sure why he does so. When I check "Used by composite" off on the "Tilemap collider 2D" it seems to work decent. But then my enemy is walking through the "foreground" tiles. So it's a lose lose. It's after he jumps he gets stuck and his feet are down into the tiles "through" the colision collider.alt text I also have a double jump problem when though I have specific collider to my avatars feet.

I would like NOT to be able to wall jump/get stuck on the wall. I would like "Used by composite" to be checked and NOT get stuck in the ground.

Thank you so much for helping out! :) appreciate it!

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityStandardAssets.CrossPlatformInput;

public class Player : MonoBehaviour { //Config [SerializeField] float runSpeed = 5f; [SerializeField] float jumpSpeed = 5f; [SerializeField] float climbSpeed = 5f; [SerializeField] Vector2 deathKick = new Vector2(25f, 25f);

 //State
 bool isAlive = true;

 // **cache, available everywhere for a scope point of view
 Rigidbody2D myRigidbody;
 Animator myAnimator;
 CapsuleCollider2D myBodyCollider;
 BoxCollider2D myFeet;
 float gravityScaleAtStart;

 // Message then methods
 void Start()
 {
     myRigidbody = GetComponent<Rigidbody2D>();
     myAnimator = GetComponent<Animator>();
     myBodyCollider = GetComponent<CapsuleCollider2D>();
     myFeet = GetComponent<BoxCollider2D>();
     gravityScaleAtStart = myRigidbody.gravityScale;
 }

 
 // Update is called once per frame
 void Update() {

     if (!isAlive) { return; }

     Run();
     ClimbLadder();
     Jump();
     FlipSprite();
 
     Die();
 }
 private void Run()
 {
     float controlThrow = CrossPlatformInputManager.GetAxis("Horizontal");
     Vector2 playerVelocity = new Vector2(controlThrow * runSpeed, myRigidbody.velocity.y);
     myRigidbody.velocity = playerVelocity;

     bool playerHasHorizontalSpeed = Mathf.Abs(myRigidbody.velocity.x) > Mathf.Epsilon;
     myAnimator.SetBool("Running", playerHasHorizontalSpeed);
 }

 private void ClimbLadder()
 {
     if (!myFeet.IsTouchingLayers(LayerMask.GetMask("Climbing")))
     {
         myAnimator.SetBool("Climbing", false);
         myRigidbody.gravityScale = gravityScaleAtStart;
         return;
     }

     float controlThrow = CrossPlatformInputManager.GetAxis("Vertical");
     Vector2 climbveclocity = new Vector2(myRigidbody.velocity.x, controlThrow * climbSpeed);
     myRigidbody.velocity = climbveclocity;
     myRigidbody.gravityScale = 0f;

     bool playerHasVerticalSpeed = Mathf.Abs(myRigidbody.velocity.y) > Mathf.Epsilon;
     myAnimator.SetBool("Climbing", playerHasVerticalSpeed);

 }

  private void Jump()
  {
      if (!myFeet.IsTouchingLayers(LayerMask.GetMask("Ground"))) { return; }

      if (CrossPlatformInputManager.GetButtonDown("Jump"))
      {
          Vector2 jumpVelocityToAdd = new Vector2(0f, jumpSpeed);
          myRigidbody.velocity += jumpVelocityToAdd;
      }

  }

   private void Die()
   {
       if(myBodyCollider.IsTouchingLayers(LayerMask.GetMask("Enemy", "Hazards")))
       {
           isAlive = false;
           myAnimator.SetTrigger("Dying");
           GetComponent<Rigidbody2D>().velocity = deathKick;
       }
   }


   private void FlipSprite()
   {
       bool playerHasHorizontalSpeed = Mathf.Abs(myRigidbody.velocity.x) > Mathf.Epsilon;
       if (playerHasHorizontalSpeed)
       {
           transform.localScale = new Vector2(Mathf.Sign(myRigidbody.velocity.x), 1f);
       }
   }

}

le-1.png (182.9 kB)
le3.png (187.2 kB)
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by 0ColdZero0 · Jan 02, 2019 at 04:06 PM

Did you figure it out? I have the same problem with my Player's feet going under the composite collider.

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
avatar image
0

Answer by Favorlock · Nov 20, 2020 at 03:29 AM

Since I came across this I thought I'd go ahead and mention the solution that worked for me. I was having the exact same issue and what resolved this was setting the player's RigidBody2D component to have continuous collision detection. So far I have not been able to reproduce the issue after making this change. Hope this helps anyone else who runs into this issue and comes across this thread in the future.

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

197 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 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

2D Box Collider not Working 1 Answer

Trigger Collinder doesnt work with Input.GetKey 1 Answer

2d Tilemap collidor not working 0 Answers

Player get's stuck on Tilemap Collider 2D 0 Answers

Different colliders in prefabs 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