I have a box collider with a rigidbody for a 2D platformer. The player moves left and right on the X-axis using physics. My player moves left and right continuously as needed and as a result will go through walls since logically the player’s character will add or subtract 1 from the X-axis to continuously move. I saw online that I can use Raycasts to detect side collisions, but I have been told that Raycast use up a lot of resources. Since I am designing/developing for mobile I’m trying to use as little as possible resources. I also know there are ways to detect Collision.contacts as seen in the Unity - Scripting page but it’s hard to find a way to write in script form for the player character to look for when a side is hit. Need examples that are more specific to which side to look at is being hit, if that makes sense.
I am looking for advice and clarification on the Raycast resource usage and if there is a more effective way to detect side collisions.
Hope to rewrite everything in 2D later on if the 2D physics use up less resources, so any experience on this will be great.|
If anyone can give me an example to try out please post. Thank you.