How to prevent node/scene snapping to colliding node/scene's x axis when using move_and_slide?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mastmartelli

I have two parent nodes, each with a collision shape and a sprite. One is a StaticBody2d, the other is a KinematicBody2d.

My player (KinematicBody2d) uses move_and_slide to collide and has a capsule shaped collision. The bush (StaticBody2d) also has a capsule shaped collision.

When I move my player into the bush from the side, the player automatically snaps to the left or right of the bush, flush with the bush’s x axis. When I move my player to collide with the bush from the bottom or top, it does not snap to the y axis or x axis. The player does not slide along the bush’s collision whatsoever either.

I’ve only been using godot a couple days, sorry if it’s an obvious fix! Any help or insight I’d really appreciate though.

Player’s script:

extends KinematicBody2D

var velocity = Vector2.ZERO
const ACCELERATION = 15
const FRICTION = 20
const MAX_SPD = 60

func _physics_process(delta):
var input_vector = Vector2.ZERO

input_vector.x = (Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left"))
input_vector.y = (Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up"))

input_vector = input_vector.normalized() * MAX_SPD
	
velocity = velocity.move_toward(input_vector, ACCELERATION if input_vector != Vector2.ZERO else FRICTION)
	
velocity = move_and_slide(velocity)

Were you able to find an answer for this? I am having the exact same problem.
I think I am using the same tutorial that you did.

cottrellam | 2023-03-01 17:15

:bust_in_silhouette: Reply From: Faiber

Hi mastmartelll,

i dont know if this is still relevant but i had the same problem and i figured out that the scale of the CollisionShape2D of my player was not 1 but set to some random numbers. The moment i reset the values to 1 it worked out for me.

I hope this might solve your problem :slight_smile: