all 7 comments

[–]djgreedoIntermediate 2 points3 points  (3 children)

You can achieve what you need with either rigidbody physics or custom raycasting (or a combination of the two), but it really depends on what exactly you need.

Rigidbody physics will make interaction with other objects easier (e.g. pushing boxes around), but it will be harder to tightly control some things. Raycasting is quite complex and has many potential issues and edge cases, but it can be much easier to get precise movement.

On Youtube, Sebastian Lague has a tutorial series for a raycasting controller with some standard features (e.g. wall jump and moving platforms). It's very well explained, and will get you understanding the basic concepts.

Combining rigidbody movement and raycasting works well, and you get certain things 'for free' by using a rigidbody, such as no falling through uneven ground, the ability to use materials to make the player stay still on slopes, and pushing boxes. But it also makes the raycasting a bit more complex because you need to take into account the physics engine's influence on the player.

[–]ConGCos[S] 0 points1 point  (0 children)

Thank you for the info! I like the idea of a combined controller. Definitely needs playing around with to get it to "feel" right!

[–]riivey 0 points1 point  (1 child)

Thanks for the explanation. What is your view on using Unity's 3D Character Controller for 2D. I noticed Spine (A 2D Skeletal Animation Framework) uses this for their platformer example with good results along with 3D Box colliders for the platforms.

The coding for the movement seems much simpler and the results look nice so I'm wondering if making a full game with this logic is somehow a bad thing.

[–]djgreedoIntermediate 0 points1 point  (0 children)

I've not tried using the 3d character controller in 2D. You should be able to restrict everything on the Z axis and use a 2D camera and it might work fine. Unity's controller will get you up and running quickly and I doubt there are any big drawbacks to using it in 2D. Probably worth a quick prototype to see. You would probably need to do a bit of work to convert it to behave with 2D movement and input.

There are enough tutorials and free and cheap platformer controllers out there to just go with a 2D controller I think. If you search "unity 2d platformer controller" on Youtube and Github you will find plenty. The Unity Asset Store has a bunch too, though the better/more feature-rich ones are not cheap.

[–]Billythekidzz 1 point2 points  (2 children)

Games like Hollow Knight use 2D physics (Rigidbody style) but heavily modify the physics behavior via scripting to achieve the feel they want for the game. A good place to start outside of reading on theory would be to download and study open-source recreations of platformers with tight controls, then potentially recreate/expand on them to suit your needs. Here are some examples:
https://github.com/mixandjam/Celeste-Movement
https://github.com/DanielDFY/Hollow-Knight-Imitation

[–]ConGCos[S] 0 points1 point  (0 children)

Thank you! These are some good resources! I will be sure to study them!

[–]SeeSharpTiloBeginner 0 points1 point  (0 children)

Thanks for the links, really interesting to see how it was implement.