• 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
1
Question by Biligoba-YusufMetindogan · Dec 26, 2019 at 04:35 PM · collisionphysicslevel-designfalling-through-floorprimitive colliders

Moving Object with a Rigidbody and Capsule Collider falls from the crack between two Box Colliders.

Hi, I'm currently working on a 2.5D Platform game where the environment is 3D but the game is played on 2D. I've come to work out my own physics system (except Collision) since Unity's own physics feels weird on platforming games (such as moving character with Rigidbody.AddForce). I'm designing levels like it is a tilemap, so my levels looks like this in general:

untitled-2.png

The problem is that my player object falls through the crack between these Box Colliders. The player object has Rigidbody and a Capsule Collider on it, and I'm moving my player via transform.position. I've made minor changes on Unity Learn's 2D Character Controller tutorial sample code. Here is the part of my code where I move my controller:

 private void FixedUpdate()
     {
         if (ControlsOn)
         {
             // X Movement Calculation
 
             movementVector = Vector3.zero;
 
             movementInput = InputManager.Instance.Controls.LustControls.Move.ReadValue<float>();
 
             if (movementInput > 0.5f) movementDirection.x = 1;
             else if (movementInput < -0.5f) movementDirection.x = -1;
             else movementDirection.x = 0;
 
             velocity.x = movementDirection.x * (maxVelocityX / friction) * Time.deltaTime;
 
             deltaPosition = velocity.x * Vector3.right;
 
             movementVector = deltaPosition;
 
             Move(movementVector);
 
 
             // Rotation
 
             if (movementDirection != directionMemory)
             {
                 // TO DO -> Do rotation
             }
 
 
             // Y Movement Calculation
 
             movementVector = Vector3.zero;
 
             if (velocity.y > 0.0f) movementDirection.y = 1;
             else if (velocity.y < 0.0f)
                 if (!isGrounded) movementDirection.y = -1;
                 else movementDirection.y = 0;
 
             velocity.y += Physics.gravity.y * gravityModifier * Time.deltaTime;
             velocity.y = Mathf.Clamp(velocity.y, minVelocityY, maxVelocityY);
 
             deltaPosition = velocity.y * Vector3.up;
 
             movementVector = deltaPosition * Time.deltaTime;
 
             Move(movementVector);
 
             directionMemory = movementDirection;
         }
     }

And here is the Move() function:

 private void Move(Vector3 motion)
     {
         transform.position += motion;
     }

I tried grouping meshes with ProBuilder tool, tried to give my level's ground a single Mesh Collider like a terrain but that also didn't work because of the concave meshes' surfaces are made of triangles (which makes the mesh have more cracks on it). I'm stuck on this for over a week now and thought I should give a shot on the community. So I'm open for any advice on the structure or the problem. Thanks! :)

untitled-2.png (64.5 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

Quickly moving cubes fall through quad floor 3 Answers

2D Collision not working! (child sprites colliders) 1 Answer

Help with 2D Hit Detection! 0 Answers

Mouse Movement with physics 1 Answer

I got a problem with using the OverlapseSphere() method inside a different PhysicsScene 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