Long story short: I need collision but I don’t need unity physics affecting my player because it’s a top-down mobile 2d puzzle game. I’ve have read multiple times that you should avoid moving player which does not have a rigidbody2d attached because performance is horrible. So then how the hell should I move my player? ( I have tried to set rigidbody2d to kinematic but then it just ignores collisions)
First of all, it is bad to move a rigidbody directly by moving it’s transform. It’s okay if you move it using rigidbody methods.
You can move an object that doesn’t have any rigidbody, and the performances are okay (It wont make the computer bug). If you do that this way, you have to handle collisions yourself (When your player touches a wall collider, you disable him from walking in the direction of that wall). The issue is, if the player move really fast, you will go through walls just a little bit (unless you code a way to make that impossible using distance checking and raycasts).
The “easiest way” in my opinion is to use rigidbodies . A rigidbody set to dynamic, but with a gravityscale of 0.
Then you move it by modifying the velocity directly. (As you don’t need physics, it is okay to do that i believe).
For example , a rigidbody with a velocity of Vector2(0,-1), will “walk down” one unit per second.
If you move a gameobject using rigidbodies, you should avoid moving it using “Transform.translate” at the same time.
If you move a rigidbody using velocity directly, you should avoid any “Rigidbody.Addforce” .
public class player Monobehaviour
{
Rigidbody2D _rigidbody;
/*=>*/ _rigidbody.velocity = Vector2.up; //the player will go up
/*=>*/ _rigidbody.velocity = Vector2.up * -1; //The player will go down
/*=>*/ _rigidbody.velocity = Vector2.right ; //The player will go right
/*=>*/ _ rigidbody.velocity = Vector2.right *-1; //The player will go left
}