Using Physics in a 2D top-down game

Godot Version

4.2

Question

Hi everybody, i’m a beginner to Godot, so if i’m saying something stupid, please correct me.

I was playing with the 2D Physics, so i tried to build a simple top-down charachter and some cubes that can be moved around. Being top-down, i decided to use RigidBody2D both for the charachter and for the cubes.
I implement a WASD movement that applies a movement to the charachter (i’ve played around with both forces and impulses.

Now, while it does work, I have two problem:

  • Everything fells slippery: the square that is hit never stops, so it seems like there isn’t any friction with the ground. How to set a “global” friction (not for collision with other RigidBodies, but always applied)?
  • Hard to turn around: the players is really hard to move around as when he is fast it takes lots of time to “change” direction; i think that this problem is connect to the first one, but if it isn’t, please tell me.

This is my code:

func _input(_ev):
	if Input.is_key_pressed(KEY_W):
		var player_rigidbody = get_node("PlayerRB2D")
		player_rigidbody.apply_central_impulse(Vector2(0.0, -3000.0))
	if Input.is_key_pressed(KEY_A):
		var player_rigidbody = get_node("PlayerRB2D")
		player_rigidbody.apply_central_impulse(Vector2(-3000.0, 0))
	if Input.is_key_pressed(KEY_S):
		var player_rigidbody = get_node("PlayerRB2D")
		player_rigidbody.apply_central_impulse(Vector2(0.0, 3000.0))
	if Input.is_key_pressed(KEY_D):
		var player_rigidbody = get_node("PlayerRB2D")
		player_rigidbody.apply_central_impulse(Vector2(3000.0, 0.0))

Thanks in advance to everybody.

If it is a player the best node for it is the character2D node

To stop the slipperiness of the movement you probably need to add some linear drag. The options for that are in the inspector (range 0 to 1, something like 0.2 usually works quite well).

The second issue will also probably be fixed by the above as well.

Its basically newtons third law , everything that has an action has an equal and opposite reaction. If you are adding impulse in one direction thats exponential, so to move back in the other diection you have to apply equal force, it soon adds up.

You probably want to limit the force as well if the linear velocity is over a certain amount.