0 votes

I have a CharacterBody2D, animated sprite and collision shape as children, that moves with a script and emits a signal on collision:

extends CharacterBody2D

@export var speed = 300
var screen_size = Vector2(1152, 648)

signal car_crashed

func get_input():
    #if Input.is_action_pressed("shift"):
        #speed = 400
        #speed = 300

    var input_direction = Input.get_vector("left", "right", "up", "down")

    velocity = input_direction.normalized() * speed
    position.x = clamp(position.x, 0, screen_size.x)
    position.y = clamp(position.y, 0, screen_size.y)

func _physics_process(delta):
    var move = move_and_slide()
    if move:

The signal is connected to a Node2D in the main scene, which reloads the scene when the CharacterBody2D collides with something:

func _on_car_car_crashed():

When moving up, left, or right this works as intended, however when moving down the collision doesn't seem to trigger.

The bodies that it collides with are also CharacterBody2D which are moved by a script:

extends CharacterBody2D

var screen
@export var speed = 300

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _physics_process(delta):
    velocity = Vector2(0,speed)

func _on_visible_on_screen_notifier_2d_screen_exited():

Rather than colliding as intended, it seems to push the object. If I try to move up the collision is detected and the scene is reloaded, but I'm at a loss on how to handle this.

video example (notice powerlines)

Godot version 4+
in Engine by (23 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.