Devlog 4
Today was a really really painful day! Lots of horror
So since yesterday, I made it so the character isn’t clamped to the screen, and the camera can travel with the player now using a really cool node : a 2D camera
I was working on a tilemap for the background, but I realized at this moment, it’s not really the focus and I wasted 20 minutes on it for the time being because it didn’t work, so I transitioned to the weapons system.
Making a sword was a somewhat easy part. Just make it collide with another object’s collision box, check if is an enemy, and if it is, then activate that enemy’s damage function. Simple enough.
The hard part? Making it actually follow the player, rotate so they aren’t in the same place, then stab out at the closest enemy without overlapping on the same enemy.
So each weapon is instantied and added to the player, under a new node called weaponHandler to just make it easy to grab them. Anything under the “player” node travels with the player. Then the weapon is rotated by 360 divided by the number of weapons, multipled by index. However, there is now an issue. They’re all at the center of the character. I attempted positioning each separately, but now they all centered 60 pixels to the right at different angles.
When looking up how to position instantiated items at different positions and angles around an existing node, I couldn’t really find anything helpful. Eventually I used Google Gemini to figure it out. The answer lied within the weapon node.
So the sprite and collision box have to be each individually changed in position rather than the whole sword; The weapon is rotated a number of degrees, however changing it’s x-axis position will do it relative to the player, which is unangled. Positioning the sprite and collision box is relative to the sword, with a angled x axis, will give different positions, since each sprite/collision would have a different position relative to their angled sword. Its kinda hard to explain, but I understand it now.
Moving on, tweening was also somewhat difficult. I wanted the sword to move smoothly and stab the closest enemy. All the actual function itself does is move between the normal position and new position (towards enemy). There’s a look_at function which rotates the sword. All I needed was the tween. Now I did not understand how it worked in junction with the rotation. I looked to Gemini, which added a 2DVector; It gets the rotation of the sword and has it move out 60 pixels from it. I don’t understand vectors entirely, never studied them, which I should probably do. Then I needed to get the closest enemy (rather than just towards any enemy)
Getting the closest enemy wasn’t hard to make thankfully.
All I have to do is search through the enemy group, and find the closest distance enemy. I realized every sword would angle towards the same enemy at first, so I made a list which appended the targeted for one to prevent other swords from taking the same one by comparing each enemy to the list.
Honestly was a very hard day; But I got the hard part done. Making new sword variants won’t be hard. In my weapon function I already added a “weapon state” which for my sword, I can add more damage or attack speed just for each state, with a new sprite.
I may add a few new enemies and make a round system. I’ll try to get this game in a working state, then I might move on for a bit, because man that weapon system and tweening burnt me out.
Cya tomorrow!