I am making a action-puzzle game in which two kinematicBody2Ds are
controlled at the same time and they move in the opposite direction.
If I press left key one of them will move in left but the other one
will in the right.
They can't collide with each other as they are in different collision layers. When I run it after sometime both the bodies stop moving but the game still is running. Here's the code of both the bodies
extends ACTOR_SCRIPT#Boy Script
func _physics_process(delta):#CHECK EVENTS BELOW EVERY TICK(SECOND)
#gravity-
velocity.y += gravity
#input-
if Input.is_action_pressed("move_right"):
velocity.x = walk_speed
elif Input.is_action_pressed("move_left"):
velocity.x = -walk_speed
else:
velocity.x = 0
if Input.is_action_pressed("jump") and is_on_floor():
velocity. y = -jump_force
else:
velocity.y += gravity
#movement-
move_and_slide(velocity, Vector2.UP)
Movement script for kinematicbody 2D(A)
extends ACTOR_SCRIPT
func _physics_process(delta):#CHECK EVENTS BELOW EVERY TICK(SECOND)
#gravity-
velocity.y += gravity
#input-
if Input.is_action_pressed("move_right"):
velocity.x = -walk_speed
elif Input.is_action_pressed("move_left"):
velocity.x = walk_speed
else:
velocity.x = 0
if Input.is_action_pressed("jump") and is_on_floor():
velocity. y = -jump_force
else:
velocity.y += gravity
#movement-
move_and_slide(velocity, Vector2.UP)
Movement script for kinematicbody 2D(B)
I just don't understand what is happening ,plz help me out.