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 juancarlosthe4th · Jun 14, 2017 at 07:37 PM · rotationcollisionrigidbody2d

Best practice for avoiding bad collisions when rotating a Rigidbody2D player?

I'm building a 2D Platform game where my player spins 360 degrees when they jump. I've implemented the 360 spin several different ways, all of which result in different tradeoffs and bugs. I want to get some advice about the best way to deal with this long term for a non-trivial game.

Description of my game:

  1. A player has a RigidBody2D with three colliders:
    1. Head = CircleCollider2D

    2. Torso = BoxCollider2D

    3. Feet = CircleCollider2D

  2. The walls, floor, and ceiling are EdgeCollider2Ds.

  3. I've set Collision Detection to Continuous on my player's RigidBody2D and that has helped a lot.

alt text

Ways To Spin 360 degrees:

  1. Spin the player directly ignoring RigidBody physics:

     float degreesToSpin = Mathf.Lerp(0f, 360f, spinRatio);
     player.transform.eulerAngles = new Vector3 (0f, 0f, degreesToSpin);
    
    

    The problem with this approach is that manual rotating will rotate right past a collision that a rigidbody might normal handle and the EdgeCollider2D on the ceiling can get stuck between the head and torso OR the player can end up on the other side ceiling's EdgeCollider2D.

    Workarounds:
    1. When spinning put a circle collider around the entire player. Downside: This creates a forcefield that creates collisions that might not normally happen and pushes the player away from walls.

    2. Each frame RayCast from my previous position to see if I have gone through anything. Downside: results in buggy looking player jumping backwards. Theoretically could create an infinite loop.

    3. Haven't tried yet: Rotate, RigidBody.Cast(), if there is a collision rollback the rotation.

  2. Let RigidBody2D do the rotation:

     float degreesToSpin = Mathf.Lerp(0f, 360f, spinRatio);
     player.rb2d.MoveRotation(degreesToSpin);
    

    This approach reduces the amount of times I get stuck on or on the other side of EdgeColliders, but that still happens once in a while.

    Downside:
    1. About 20% of the time, I get huge ricochets when a platform blocks a rotation. I want the player to spin against anything it hits, not bounce off with a large velocity. I'm guessing I can mitigate this by changing the material.bounciness coefficient or setting the velocity to a low number during OnCollision.

    2. The rotation results in some of my upward velocity getting transferred to horizontal velocity which is realistic, but I do not want it.

What is the best way to implement platformer style player spinning, on a non-trivial game?

I have much less problems with BoxCollider2Ds or anything with width. My gut tells me I should reimplement all of my world's walls as BoxCollider2Ds or PolygonCollider2Ds. This will probably save me a lot of future headaches with other types of objects going through the EdgeCollider. Is this assertion correct?

player-small.jpg (493.7 kB)
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 hexagonius · Jun 15, 2017 at 10:39 AM 0
Share

The best way would be to calculate the torque needed and alter that on the rigidbody. That would be Physics-Engine-ally 100% accurate

0 Replies

· Add your reply
  • Sort: 

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

110 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

Related Questions

Rigidbody2d not rotating 2 Answers

Jumping and reverse gravity with a Rigidbody2D (based on the Ruby tutorials) 1 Answer

Simple moving ball script 1 Answer

Rigidbody2D rotation spinning wildly when attaching by joint to another Rigidbody2D 0 Answers

Projetil rotation in straight line trajectory 2 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