Weapon not detecting static bodies at all

Godot Version

Godot 4.3 stable

Question

Super newbie here, my dagger is not able to detect static bodies at all even though it can easily detect the enemies which are character bodies and stick to them in a weird manner (which i will probably fix later) but for now it is not even registering the static bodies with the print statement, they are on the same layer and masks but for some reason the dagger just doesn’t work, i even changed to rigid but still nothing, any help would be greatly appreciated :smiley:

extends CharacterBody3D

@onready var anim_player = $AnimationPlayer
@onready var hitbox = $Dagger/WeaponHit
@onready var throw_timer = $ThrowTime

var is_attacking = false
var is_thrown = false
var is_recalling = false
var throw_speed = 20.0
var recall_speed = 30.0
var throw_direction: Vector3
var player_position: Vector3  

func _ready():
	hitbox.monitoring = false  
	hitbox.connect("body_entered", Callable(self, "_on_weapon_hit_body_entered"))

func _physics_process(delta):
	player_position = get_parent().global_transform.origin  

	if Input.is_action_just_pressed("Attack_1") and not is_thrown and not is_recalling:
		attack()
	
	if Input.is_action_just_pressed("Dagger_throw") and not is_thrown and not is_recalling:
		throw_dagger()
		
	if Input.is_action_just_pressed("Dagger_recall") and is_thrown:
		recall_dagger()

	if is_thrown:
		global_transform.origin += throw_direction * throw_speed * delta

	if is_recalling:
		recall_to_player(delta)

func attack():
	if not is_attacking and not is_thrown:
		is_attacking = true
		anim_player.play("Attack")
		hitbox.monitoring = true  

func throw_dagger():
	is_thrown = true
	is_attacking = false
	hitbox.monitoring = true
	var player_transform = get_parent().global_transform
	throw_direction = -player_transform.basis.z.normalized()
	global_transform.origin = player_transform.origin
	global_transform.basis = player_transform.basis
	throw_timer.wait_time = 0.1
	throw_timer.connect("timeout", Callable(self, "_enable_top_level"))
	throw_timer.start()
	anim_player.play("Throw")
	
	


func recall_dagger():
	is_recalling = true
	is_thrown = false
	hitbox.monitoring = true  

func recall_to_player(delta):
	var to_player = player_position - global_transform.origin  
	if to_player.length() > 0.5:
		global_transform.origin += to_player.normalized() * recall_speed * delta
	else:
		
		anim_player.play("Idle")
		is_recalling = false
		reset_to_player()

func reset_to_player():
	global_transform.origin = player_position
	global_transform.basis = get_parent().global_transform.basis  
	top_level = false
	anim_player.play("Idle")  #
	hitbox.monitoring = false
	is_attacking = false

func _on_weapon_hit_body_entered(body: Node3D) -> void:
	if body.is_in_group("Enemies"):
		if is_thrown or is_attacking:
			print("Enemy hit with dagger")
			body._take_damage(25)  #damage
			stick_to_object(body)
	elif body.is_in_group("Environment"):
			print("Dagger hit environment:", body.name)
			stick_to_object(body)

func _on_animation_player_animation_finished(anim_name: StringName) -> void:
	if anim_name == "Attack":
		anim_player.play("Idle")  
		hitbox.monitoring = false  
		is_attacking = false
		
func _enable_top_level():
	top_level = true
	print("Dagger top_level enabled.")

func stick_to_object(body: Node3D):
	is_thrown = false
	is_attacking = false
	global_transform.origin = global_transform.origin  
	global_transform.basis = body.global_transform.basis  
	hitbox.monitoring = false  

i was using jolt and i didn’t turn on that the area could affect static bodies in the project setting bruh :stuck_out_tongue:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.