Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit) (+1)
line persists indefinitely

OMG I AM AN IDIOT. I MESSED UP. Here's the code from trimming the line:

func TrimLine() -> void:
    while GetLineLength() > max_length:
        line.remove_point(0)

line is my line2D, which essentially is just for visuals. I have an Array[float] that stores all the points for detection. Here's what I should've added:

draw_points.remove_at(0)

Oh well, that is actually a pretty bad mess up on my end, considering draw_point[0] is also used to detect if the loop is complete. If you do a loop like where the initial point is far from the close loop position, it won't work.

For the enemy detection, I'm just trusting Godot's Geometry 2D functions.

func is_enemy_in_loop(enemy_position: Vector2, loop_points: Array[Vector2]) -> bool:
    var polygon = GetPolygonOutOfLine()
    if Geometry2D.is_point_in_polygon(enemy_position, polygon):
        return true
func GetPolygonOutOfLine() -> PackedVector2Array:
    var hull = Geometry2D.convex_hull(draw_points)
    return hull

For detecting loops, I just use a very hacky distance travelled + distance to draw_point[0], that fires everytime you add a draw point. I think the infinite damage from afar is all down to the draw_point[0] not being removed, as your polygon will just be really big.

Thank you so much for playing, and even spending time trying to break it! That's what makes game dev so fun.