Devlog #8

Frustrated

Posted October 9, 2023

What I've been working on

After adding a wave system, the next feature I wanted to add was a weapon to attack the enemies. This feature would consist of a few new additions to the tower scene.

First, a weapon sprite will sit on top of the tower. This weapon will have a range that will determine how close an enemy is. Once an enemy is withing range, the weapon will look at the enemy. I achieved this by using an Area2D and setting up a signal to fire when anything entered the area.

Next, once an enemy is in range, its coordinates are grabbed and fed to the weapon sprite. Using the look_at() function will change the direction the sprite is looking. This was when I ran into my first of many problems.

Frustration

Once I had this system set up, I noticed the weapon sprite would look at the first enemy, and then look in the completely wrong direction after. I set up some print statements to see where the sprite was being told to look. The coordinates I got back were extremely large and inaccurate. Initially, I was dumbfounded. I had no idea why I was getting large coordinates.

Initially, I was dumbfounded. I had no idea why I was getting large coordinates. I added a label to the enemy, and had the contents of it be the coordinates of itself. Even as I'm writing this devlog, I have no idea why this happened.

As a form of debugging, I wanted to see if I could even make the weapon sprite look in a proper direction. Instead of the enemies position, the sprite would look at my mouse position.





This at least confirmed it was possible, and that was all I needed to know. But I had to come up with another way to get an enemy's coordinates.

Shortly after I came up with a promising idea. Since I used a label to display the mouse coordinates under an enemy, I could instead get the coordinates of the label. It wouldn't be precise, but it gives the correct direction to look in.

I had high hopes for this solution, but instead of incredibly large coordinates, I was getting nothing. Visually the coordinates are correct, but when I try to pass this variable across scripts, it would become [0,0]. I deduced this to be only grabbing the coordinates of the label in its scene. Which was [0,0].

After trying solution after solution, this has been stumping me for the last few days. I've even considered changing the design of the weapon feature altogether. If I can't find a solution soon, I'll have to change the feature.

Next Devlog: #9 ›