I am trying to program a ground system similar to the game, Castle Crashers. In this game, the player walks on the ground, but a section of the screen is dedicated to the sky/background and the player cannot walk on it. I know it sounds simple, but I’m stumped and can’t find any tutorials to replicate this. I know it does not involve Unity’s tile system. Does anyone know how I can program the character to stay on/within the grass in Unity 2d, or link a tutorial?
Hey! I don’t really have a tutorial to link but I can explain how the game works. I worked on a game similar to this, a remake of an old mobile game (Zombieville USA 2) which follows the same system as castle crashers. The Player’s Rigidbody have a 0 Gravity Scale and a script that moves the rigid body velocity through the direction of either a mobile control (Unity’s Standard Assets CrossPlatform MobileControl) or WASD keys. The player’s location is restricted by box colliders (example in image). I first tried to restrict the player.y via code but I found it more successful to just use box colliders. Here’s a chunk of code that made the player move