I realize this is a broad question, but I want to make sure I’m building my game in a smart way.
I’m making a Mario-like 2D platformer, and I want to make it so that if a platform is moving/falling, enemies and objects on top move with it.
Some tutorials accomplish this by having the object detect the platform. Others do the opposite, with the platform detecting the object on top.
My 2 main questions are:
Generally speaking, should collision detection occur in the platforms or in the objects?
And what is the wise strategy for doing this? I don’t know if I should use kinematic rigidbodies and set parenting on collisions, or use dynamic rigidbodies and let the physics system handle all of it, or skip rigidbody and give raycasting capabilites to all the objects, etc.
Broad question, broad answer with some unsolicited advice…
You shouldn’t. Just wing it. It is more important that you build what you want, you have plenty of time to make it smart when you have the mechanic nailed down. I’m serious.
Whichever is more convenient or more efficient in CPU usage. Generally doesn’t matter.
Doing it any way and learning that you will refactor your game code 1000 times no matter how “smart” you built. Thinking ahead is a waste of time 99 out of 100 times. (after you built a considerable amount of software you will develop an intuition what you want to do generally in advance, but you can’t avoid refactor entirely)
Whichever feels better for your game. Build all of them and play with it and see which you can stitch together with your blood and sweat to be fun to play.
Thanks for your input! I was thinking there might be some “best practices” in the context of a 2D platformer, but you’re probably right that I just need to try some things and see what works as the game grows.
I’m leaning toward putting the collision detection code in the objects rather than in the platforms. That feels like it makes more sense to me at this stage.