I’m making a top-down shooter and I’m trying to use Physics2D.CircleCast around the player to detect whether there is anything in the way, to stop the player from being able to move.
Currently the player moves by calling new Vector3 on update, so using Unity’s Rigidbody2D system wouldn’t work.
This is the way I tried using circlecast (will paste more code if needed):
My idea was if the circlecast returns true (colliding with something), it disables input.
The editor did not throw any errors with this so I assumed it returned a bool and it was fine, however it would not interact with any of the other colliders in the scene.
I’m sure the process would be very easy by just making the player with a Rigidbody2D and applying velocity instead of changing the vector position. However I wanted to make this game without using Rigidbodies.
If anyone would be willing to share any insight about CircleCast or any alternative way of going about this, I’d greatly appreciate it!
So many times I see this kind of statement and it’s 100% always wrong due to lack of understanding. A Rigidbody2D has three body-types and for a good reason. You don’t HAVE to use a Dynamic body-type, you can use a Kinematic one if it’s moving and Static if it’s not. If you don’t do this then you cannot “move” a Collider2D.
Only Rigidbody2D move in physics, colliders are attached to them. What you’ll be doing is modifying the Transform on a Static (non-moving) collider and this simply causes the collider(s) to be recreated at the new position which is costly and pointless.
Add a Rigidbody2D, set it to be Kinematic and drive that. Stop trying to bypass physics and creating a situation where you’re gaining nothing and loosing performance!
If you add a Rigidbody2D and set it to Static then it’s the exact same thing except you can control the position of the Rigidbody2D here.
The only reason you can add a Collider2D without a Rigidbody2D is for convenience when laying out static (non-moving) colliders. It’s not there so save you performance.
Thanks for the extra bits of knowledge, but I want to be able to do this with some kind of casting (e.g. the circle I attempted) instead of driving a Rigidbody.
I don’t mean to disregard your reply sir. Just that I said in the text you quoted, I want to do this without using Rigidbodies.
Not because I think they are better or worse or the proper way to do it, but I’m still fairly new to Unity and I’m making random silly games every so often to try new / different things that I didn’t before.
If you have any useful info about casting or circlecast specifically, I’m all ears