- Edited
Basically title. Why is it coming up with an error? Did i type smth wrong? I cant stop it from detecting the tilemap or it just falls through,..
EDIT: I fixed the bug, But now the same thing happens with the player...
Basically title. Why is it coming up with an error? Did i type smth wrong? I cant stop it from detecting the tilemap or it just falls through,..
EDIT: I fixed the bug, But now the same thing happens with the player...
Apparently the very first item this area is entered(overlapping with) by is the tilemap. You might want to make sure that they are on different collision layers. If you need them to be on the same collision layer for some purposes you can have one been on say layers 1 & 2 while the other is only on 1 for an example and then use another if statement to check if the body entered is assigned to the relevant collision layer. That might resolve it.
Also, my bad, you might have to use .get_name() instead of .name(). I misrecalled(or it was changed in godot 4, also possible).
I have fixed that, It's just that its colliding with the player and crashing now
Maybe share the whole script in here.
Heres the goomba script:
extends CharacterBody2D
@export var SPEED = 300.0
# Get the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
var direction = Vector2.RIGHT
func _ready():
$AnimatedSprite2D.play("Walk")
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta
var found_wall = is_on_wall()
if found_wall:
direction.x *= -1
$AnimatedSprite2D.flip_h = direction.x > 0
velocity.x = direction.x * SPEED
set_up_direction(Vector2.UP)
move_and_slide()
move_and_slide()
func _on_area_2d_body_entered(body):
if body.name() is "player":
if $Player.velocity.y < 0:
print("Found!")
Just read the last part sorry about that lol, I Set it to get_name and now it throws an error with 'is'.
I set it to == and it works, thanks!
SuperMatCat24 I set it to == and it works, thanks!
That's great!
...though looking at the above post with the pasted codeblock I wonder why you have move_and_slide()
twice there, also the set_up_direction(Vector2.UP)
method call there makes me think you didn't include the whole thing. I was asking for it since I was going to try and set up a test project duplicating the crash.