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 Dagless101 · Nov 11, 2016 at 01:40 PM · 2d2d-platformerrigidbody2dboxcollider2d

Rigidbody2d getting stuck when moving horizontally at random points! Can't figure it out :(

Hi there,

This is my first time posting so thankyou so much to anyone that can help. This has happened in the last two games i've tried to make and its driving me nuts!

I've got a RigidBody2D being controlled by Input.GetAxisRaw and a simple move method.

 void Update () {
 
         Move(Input.GetAxisRaw("Horizontal"));
         if (Input.GetButtonDown("Jump"))
             Jump();
     }

 public void Move(float horizontalInput)
     {
         if (horizontalInput == 1)
         {
             santaAnimator.SetBool("running", true);
             santaSprite.flipX = false;
             santaCollider.offset = new Vector2(-0.84f, santaCollider.offset.y);
         }
         else if (horizontalInput == -1)
         {
             santaAnimator.SetBool("running", true);
             santaSprite.flipX = true;
             santaCollider.offset = new Vector2(0.84f, santaCollider.offset.y);
         }
         else
         {
             santaAnimator.SetBool("running", false);
         }
 
         Vector2 moveVel = santa.velocity;
         moveVel.x = horizontalInput * speed;
         santa.velocity = moveVel;
     }

It flips the sprite and also offsets the boxcollider to make sure its in line with the sprite.

However, at seemingly random points whilst running the game, the Rigidbody (santa) will just stop moving horizontally, even if the key is is held down. The 'running' animation continues, supposedly meaning that the Move method is still working and I can jump 'over' this seemingly invisible barrier and walk back through it the other way, but itll most likely happen again in a different point some time later. The only other thing the Rigidbody is colliding with is a 'ground' prefab that has a simple BoxCollider2D on it, and thats literally it.

My repo is here: https://github.com/Dagless101/snow

I'm more than happy to upload the game as a whole somewhere if you'd like to take a hollistic view. It isnt much at the moment.

Thankyou to anyone who has a look, this is driving me mad and I'm out of ideas as to what is causing it.

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

Answer by tanoshimi · Nov 11, 2016 at 02:15 PM

It's quite easy to get "corners" of colliders stuck on each other - you mention that this is a box collider rubbing alongside another box collider - does your invisible wall happen at the edge of a collider? The normal solution is not to use a box collider on your player but use a circle collider instead (which is also slightly cheaper)

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 Dagless101 · Nov 11, 2016 at 02:55 PM 0
Share

You are a hero!! Im using two overlapping circlecolliders now and it seems to have resolved the problem. Thankyou thankyou!

What a strange thing...

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

Character input works but gets dragged back for no reason 1 Answer

My RigidBody2D+BoxCollider2D is getting stuck on corners 1 Answer

Scale collider from one side for 2d Object 0 Answers

2D Colliders bug. 1 Answer

Rigid Body Movement (Mobile Issue) 3 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