Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | FortunePilot |
Hi all,
I am trying to make a topdown 2d game in which the player collides with walls. At first I worked with a regular area2D, but according to an answer to this question asked before: https://forum.godotengine.org/16587/how-do-i-create-collision-with-walls, it was easier to use a kinematicbody2d and a staticbody2d to minimize code. I then followed this article: Kinematic character (2D) — Godot Engine (latest) documentation in English to try to make my collision work. This however doesn’t work, as my player can still move through my intended walls.
I tried to use this code for my player:
extends KinematicBody2D
const SPEED = 400
func _physics_process(delta):
var velocity = Vector2()
...
# Movement input
...
if velocity.length() > 0:
velocity = velocity.normalized() * delta * SPEED
if move_and_collide(velocity):
print("Collide!")
to test whether the collision is actually working, but this prints nothing. For both the player and my tiles the collision layers and masks are set to the top left box.
Is there anyone who knows what I’m doing wrong?
Thanks in advance!
~FortunePilot