I'm quite new to Godot so apologies if this is a silly question, but I wasn't able to find a solution online.
I'm trying to rotate a RayCast2D and once it's rotated, check if it collides with something. The player can rotate the character and attack using the same key, e.g. pressing "W" will result in the character looking up and attacking up as well. The issue I'm facing at the moment is that it seems like the collision is checked before the rotation happens. I'm using the following two lines of code to do this:
attackRay.rotation_degrees = rad2deg(atan2(facingDir.y, facingDir.x))
where attackRay is the RayCast2D and facingDir is the direction the character should be turning to, determined by the user input. If there is an object above the player and I press "W", the raycast is rotated perfectly fine but the console prints "False". If I press it again, it prints "True". If I then press e.g. "S" the raycast points downwards but the console output is "True" again, although there is no object to collide with. Pressing "S" again outpus "False".
The point is, apparently checking for the collision happens prior to the rotation even though in the script rotating the raycast is done before.
I've been trying to fix this for quite some time now but can't seem to get it to work. Any input would be highly appreciated.