How do I "fill" a hitbox? 2D game

Godot Version

4.3 Stable

Question

Watch the video for context ^^^

Code for the bullet:

extends CharacterBody2D

# These variables are set by the player scene
@export var speed: float
@export var pos: Vector2
@export var rot: float

@onready var hitbox: Node = $BulletHitbox
@onready var timer: Node = $Timer

var collision: Object

func _ready():
	global_position = pos
	global_rotation = rot
	timer.start()


func _physics_process(delta):
	if collision:
		hitbox.disabled = true
		return
	velocity = Vector2(speed, 0).rotated(rot)
	collision = move_and_collide(velocity * delta)


func _on_timer_timeout():
	queue_free()

Is there any way to “fill” the hitboxes and avoid the bullets going through the insides of the hitboxes?

I am not getting your question… what do you want to achieve ?

I want to make it so the bullet doesnt go through the hitbox and instead goes to the top of the hitbox

you’re spawning it inside the hitbox, so I think it is only hitting it on exit. You may be able to check if the area and it are touching, and then stop the bullet

1 Like

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