why do KinematicBody2Ds move when the player influences them?

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

Hello, I’m a kind-of-beginner to godot 3 (I have some experience) and I have noticed that when I put move_and_slide(velocity, FLOOR) (FLOOR is Vector2(0, -1) and velocity is my movement) inside of a kinematicbody2D script, If the player walks against the kinematicbody2D, it will start moving constantly by just a tiny bit, and if the player tries to walk on top of it, after being on the kinematicbody2D for a little bit the object just falls right through! My game pretty much relies walking on kinematicbody2Ds to work, so am I doing something wrong with move_and_slide, or is it just a glitch in the engine?

Thanks!

Could You parse code sample of how do You handle input and movement ?

Vrzasq | 2019-09-02 11:52

yes I can but I don’t have access to my PC right now, but I will later today
I’ll do it as soon as I can

3ngin33r8086 | 2019-09-02 13:04

if Input.is_action_pressed(“ui_right”):
$CollisionPolygon2D.scale = Vector2(1, 1)

	$AnimatedSprite.flip_h = false
	if on_ground == true:
		vel.x = min(vel.x + acc, regSpeed)
		$AnimatedSprite.play(walk)
	else:
		vel.x = min(vel.x + acc - 3, regSpeed)
		$AnimatedSprite.play(idle)
	
	
	
	
		
		
elif Input.is_action_pressed("ui_left"):
	$CollisionPolygon2D.scale = Vector2(-1, 1)
	$AnimatedSprite.flip_h = true
	
	if on_ground == true:
		vel.x = max(vel.x + -acc, -regSpeed)
		$AnimatedSprite.play(walk)
	else:
		vel.x = max(vel.x + -acc + 3, -regSpeed)
		$AnimatedSprite.play(idle)
	
	
	
else:
	vel.x = lerp(vel.x, 0 , 0.2)
	$AnimatedSprite.play(idle)


if on_ground == true:
	
	gravity = 10
	idle = "idle"
	$AnimatedSprite.offset = Vector2(0, 0)

#jump code

#regular jump
if Input.is_action_pressed("jump"):
	if on_ground == true:
		jump()
#if player releases jump key before max jump is reached, start falling
if Input.is_action_just_released("jump"):
	jump_cut()

	
vel.y = min(vel.y + gravity, 350) #makes the player fall with gravity

vel = move_and_slide(vel, FLOOR) #makes the player move with coded physics

3ngin33r8086 | 2019-09-03 23:04

and the movement for the non-player kinematicBody2D is:

extends KinematicBody2D
var gravity = 10
var vel = Vector2()
var FLOOR = Vector2(0, -1)

func _physics_process(delta):
vel = move_and_slide(vel, FLOOR)
vel.y += gravity

3ngin33r8086 | 2019-09-03 23:05