- Home /
2D Character Controller Movement Issues
So I decided for my newest project to try and code my own basic 2D bounding system for the objects in my game. I find that being able to alter the objects transform rather then using physics forces just allows me to get things moving around in a way that feels good. I figured using this kind of movement bounding system in conjunction with triggers I could create a general 2D platforming system that felt good to the player. Where I am having some difficulty is in detecting bounds correctly at higher movement speeds. First off let me post my code.
I have 2 classes, a moveable object that I planned to use to move around various sprite objects, and a character specific controller that derives from MoveableObject. I posted them over to github to avoid any code formatting issues over here.
It seems to work pretty well most of the time! The main issue seems to be when I am applying movement forces that are larger then 2 or 3. Sometimes with movement of 5 or more the player object ends up embedded into the ground. Not very deeply, but enough for the lower collision probe rays to collide with the floor and prevent X axis movement. Should I be doing this stuff in FixedUpdate? Am I somehow using transform.Translate incorrectly? At one point I thought I factored in some code to never pass a movement value into the method actually moving the character that was greater then the characters distance to an object. I have since commented it out since it didn't seem to fix the problem. Any insights would be really helpful. I've watched some youtube tutorials where people use systems similar to this and I can't seem to see any differences between our methods that would cause something like this to happen... I've increased the scales to the point where I feel like I can discount float inaccuracy being the culprit as well.
My current game scale has the characters sprite at exactly 2 grid units tall. This feels like a pretty good scale in general for doing 2D level design but I guess I could be completely off?
Your answer
![](https://koobas.hobune.stream/wayback/20220613134851im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Layer Mask on raycast2d not working? 1 Answer
Raycast for a 2D objects 0 Answers
2D sidescroller shooting 1 Answer
Finding any objects below or above object at ANY POINT? 1 Answer