Godot Version
4.4.1
Question
basically the title
sometimes the raycast dosent recognize that there is a physicsbody collision when updating. I’ve tried inserting await get_tree().process_frame
some places in the code but that didnt seem to have an effect
for clarification it seems to be the spell_raycast that has the issue and not the spell_raycast_bounce
(please ignore the blue path thats pointing down and to the right I forgot to disable paths)
heres whats happening :
White collision is StaticBody
Blue collision is CharacterBody
Code:
func _physics_process(delta : float) -> void:
ray_bounce()
func ray_bounce() -> void:
# ray cast
global_position = parent.global_position + parent.spell_direction.normalized() * 30
if spell_raycast.is_colliding():
if spell_raycast.get_collider() is StaticBody2D:
var collision_normal = spell_raycast.get_collision_normal()
var collision_pos = spell_raycast.get_collision_point()
var reflected_dir = spell_raycast.target_position.bounce(collision_normal).normalized()
var ray_length = spell["size"] - (spell["size"] - to_local(collision_pos).length())
print("IS COLLIDING")
spell_raycast.target_position = parent.spell_direction.normalized() * ray_length
spell_raycast_bounce.global_position = collision_pos
spell_raycast_bounce.target_position = reflected_dir * spell["size"]
elif spell_raycast.get_collider().is_in_group(hostile):
print("is colliding with enemy")
var collision_pos = spell_raycast.get_collision_point()
var ray_length = spell["size"] - (spell["size"] - to_local(collision_pos).length())
spell_raycast.target_position = parent.spell_direction.normalized() * ray_length
else:
print("not colliding")
spell_raycast.target_position = parent.spell_direction.normalized() * spell["size"]
spell_raycast_bounce.position = spell_raycast.target_position
spell_raycast_bounce.target_position = Vector2.ZERO
I cannot for the life of me figure out why this is happening