How to push characterBody3D

Godot Version



How to write code that will make characterBody3Ds able to push each other? I tried this but not too successful.

func _physics_process(delta):
	var collision = move_and_collide(velocity * delta)
	if collision:
		var collider = collision.get_collider()
		if collider.is_in_group("player_2"):
			collider.velocity.x = velocity.x
  • Is this 2D ? 3D ?
  • The object you attached the script to should at least have their mask set to the layer your (“player_2”) collider is in.
  • You might want to print details if there’s any collision first, and not just for specifically for “player_2”.