Godot Version
4.2.1
Question
Hello, guys. I’m implementing a simple demo where the player can kick blocks which should slide until they either hit a wall or another block. The blocks were implemented as CharacterBody2D, since I only plan on moving them through code. I’ve placed them using a grid, but when the player kicks a block that should slide besides another block, it instead collides. Both player and blocks have the motion mode set to “Floating” and the floor layers for them have been all disabled.
The project is available on GitHub. I’ve tried setting a safe margin, switching between move_and_collide and move_and_slide and adjusting other CharacterBody2D settings with no success. Does anyone know what I’m missing here?
Here is the code for the block:
extends CharacterBody2D
const SPEED := 500
func _physics_process(delta: float) -> void:
var collision = move_and_collide(velocity * delta)
if collision:
velocity = Vector2.ZERO
func kick(direction: String) -> void:
if direction == "up":
velocity = Vector2(0, -SPEED)
elif direction == "down":
velocity = Vector2(0, SPEED)
if direction == "right":
velocity = Vector2(SPEED,0)
elif direction == "left":
velocity = Vector2(-SPEED,0)