0 votes

Hello all,

Im stuck trying to figure out what im missing, since i still don´t understand fully the use of raycasts2D.

Im generating all my scenario elements in my _ready() func, before the player can do anything, but when i place obstacles, i need to know if those elements are blocking a path i generate also for the scenario. All procedural.

My problem comes when i discovered that my raycast2D is not colliding with my obstacles when i instance them (If they are there since the beggining of the scene without creating them by code all is right).

Here is the code of a test scene im using to find a way to get that desired collision.

extends Node2D

var verticalSpike = load("res://scenarios/obstacles/verticalSpikeWall.tscn")

func _ready():
    verticalSpike = verticalSpike.instance()
    verticalSpike.position = Vector2(800,500)

    if $RayCast2D.is_colliding():
        print("no collision")

As you see there, im instancing an scene of an obstacle that have an area2D to collide with. The raycast is passing through it but not colliding.

And yes, they have the same mask, raycast is enabled too. If i use _process(delta) the raycast collides, but i need to check in _ready() but im not finding the way to achieve this (if this is possible, if not i should find another way to check if an obstacle is blocking the path for the scenario)

Godot version v3.2.1 - stable
in Engine by (14 points)

1 Answer

0 votes

maybe instead of var and load use onready var and preload, maybe the object is being instanced after the raycast check? just a thought.

by (430 points)
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 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 webmaster@godotengine.org with your username.