Player stuck in wall

Godot Version



Hi, I have my Player (KinematicBody2D), TileMap and a vehicle (KinematicBody2D or RigidBody2D?). If player collide with the vehicle, I want to push him in front of the vehicle. Now, the vehicle can push the player through the TileMap. I want to avoid stucking in the TileMap, so in this case I want to push him to some side and let the vehicle drive (yes, I want vehicle to go through the TileMap). How can I do that?

Thanks for advice

Here is code of vehicle:

extends CharacterBody2D

const speed = 100

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
	var velocity = Vector2.DOWN * speed * delta

Here is code of player:

extends CharacterBody2D

@export var speed = 1600
@export var cur_hp : int = 10
@export var max_hp : int = 10
@export var min_hp : int = 0

# Called when the node enters the scene tree for the first time.
func _ready():

func _physics_process(delta):

func get_input():
	var input_x = 0
	var input_y = 0

	if Input.is_action_pressed("ui_left"):
		input_x -= 1
	elif Input.is_action_pressed("ui_right"):
		input_x += 1

	if Input.is_action_pressed("ui_down"):
		input_y += 1
	elif Input.is_action_pressed("ui_up"):
		input_y -= 1

	if input_x < 0:
		velocity.x = -speed
	elif input_x > 0:
		velocity.x = speed
		velocity.x = 0

	if input_y > 0:
		velocity.y = speed
		if input_x == 0:
	elif input_y < 0:
		velocity.y = -speed
		if input_x == 0:
		velocity.y = 0

	if velocity.x == 0 and velocity.y == 0:

it should be CharacterBody2D

also what kind of game is this, is it top down or platformer?
because the “wall” is different for these 2

figured it should be top-down,
Try set the player characterBody2D’s property to
floor_block_on_wall = false

also you could set the player to either move to side when it detect collision of a wall (if the direction of player being moved to is to the right and the wall is on the right, then it could either move up or down, by adding velocity to the player)