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 agiro · Aug 10, 2016 at 01:02 PM · collisionphysicsplatformercontrolgameplay

Object sticks to the side of the collider

Greetings, I'm making a 2D platformer. I'm using 3D physics in it (100% 3D physics, no mix). The problem is that when the player jumps from a ground to another, occasionally the character hits the side of the platform. In these cases the character gets sticked to the side (until I let the move button go). Either way this makes the gameplay unbearable. How to solve this? I'm using this as reference where the tutor faces this issue as well by the way. My platforms are 3D boxes, my character is a 3D capsule. Everything else I used like in the tutorial I posted. I would perefer the player to slide up to the box if that's possible, if not, killing the character is fine as well. All the help appreciated.

Some code: my character movement:

 void Start ()
     {
         //in dev: setting the pos so I don't have to play it over again.
         gameObject.transform.position = new Vector3(47.1f, -4.18f);
         //
         jump = true;
         moveForce = 36.50f;
         maxSpeed = 8.0f;
         jumpForce = 1000.0f;
         grounded = false;
         anim = GetComponent<Animator>();
         rb = GetComponent<Rigidbody>();
     }
     
     // Update is called once per frame
     void Update ()
     {
         grounded = Physics.Linecast(transform.position, groundCheck.position, 1 << LayerMask.NameToLayer("Ground"));
 
         if(Input.GetButton("Jump") && grounded)
         {
             jump = true;
         }
     }
     void FixedUpdate()
     {
         //constant movement forward. needs to be updated because of the fall. 
 
         Moving();
 
         
     }
     void Moving()
     {
         float h = Input.GetAxis("Horizontal");
         rb.velocity = new Vector3(maxSpeed * h, rb.velocity.y);
         //if(h * rb.velocity.x < maxSpeed)
         //{
         //    rb.AddForce(Vector3.right * h * moveForce);
         //}
         //if (Mathf.Abs(rb.velocity.x) > maxSpeed)
         //{
         //    rb.velocity = new Vector3(rb.velocity.x * maxSpeed, rb.velocity.y);
         //}
         if (jump)
         {
             //anim.SetTrigger("Jump");
             rb.AddForce(new Vector3(0.0f, jumpForce));
             jump = false;
         }
     }


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

Answer by LightningStorm102 · Mar 17, 2019 at 08:49 PM

Hello!


The answer is found in this video: youtube.com/watch?v=QGDeafTx5ug∈dex=2&list=PLBIb_auVtBwBotxgdQXn2smO0Fvqqea4-&t=0s


If you don't want to watch it, here is the answer in a nutshell: Make a new physics material. Then set it's friction to 0. Now select your player and drag this material into the material slot of the Rigidbody component.

This should fix your problem. :)

Comment
Add comment · Show 2 · 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 logicandchaos · Jul 17, 2020 at 03:45 PM 0
Share

Hey I'm having a similar issue in 2d where when my player touches my enemy he gets stuck and I can't walk away or anything! I have seen lots of people give your solution to the problem, but when I used it I still had the problem and worse my characters, just slide around the map.. the other solution I have seen is to make boxes out of edge colliders, idk if that works cause when I tried it my characters stopped colliding with the ground.. DO you know any other fixes?

avatar image logicandchaos · Jul 17, 2020 at 04:12 PM 0
Share

I adjusted Physics 2D and to set the Velocity Threshold as low as I could go and physics2d and increase the default contact offset. Both had no effect, A fix I found was to add bounciness to the material, and I think lowering friction helped a bit, but bounciness of about .36 fixed my issue.

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

106 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

Related Questions

2D RigidBody slightly penetrates objects causing a bounce effect. 3 Answers

Friction affects ball's direction after collision 0 Answers

Physics Movement without Physics Reactions 1 Answer

Collider fires consistently, but Trigger does not? 0 Answers

Is there a way to limit animation on collision? 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