• Godot Help
  • confusion with raycast .is_colliding in input function

hey guys my first post here. im working on simple tower defence game, and right now im working on camera scene that allows to choose building by press of the mouse.
so i have perspective scene. its basically area3d with camera and raycast node.

build platform scene that is area3d with collision object as child

in perspective scene everytime player presses left mouse button game updaates raycast and sends it to new place

and something weird is happening. if raycast is colliding it should immediatly print message. but this is now what is happening. message prints only after raycast is UPDATED again

print message should be before second "to" print, but it isnt

so it seems like when raycast target to is updated, but .is_colliding check doesnt work? but if its true than when raycast position is updated second time is_colliding check souldnt print message. but it still does

  • You probably should not do ray casts in input, as they run at a different update rate than both _process and _physics_process.

    Most likely the issue is that the ray cast logic needs to be in _physics_process. If you need input, then set boolean flags on the _input function and then check them in _physics_process before doing the collision code.

want to clarify, in print pictures i updated raycast two times. first time i click directly on build platform, and second time i build on empty space. so first "to" print message is colliding with buildPlatform, and second isnt. .is_colliding() check activates after we updated raycast to empty space.
so im really confused

You probably should not do ray casts in input, as they run at a different update rate than both _process and _physics_process.

Most likely the issue is that the ray cast logic needs to be in _physics_process. If you need input, then set boolean flags on the _input function and then check them in _physics_process before doing the collision code.

    so i remade it and it seams to work right. thanks for help