Godot Version
v4.2.1.stable.official
Hello to all,
I am trying to recreate a 2D game I use to play back in the late 1990’s as a personal project over the Christmas/new year break where you play as a fish & try to eat smaller fish while avoiding larger fish. If the player collides with a fish smaller then themselves they will eat that fish & slightly increase in size but if a larger fish collides with the player, the player will respawn reverting back to its original size.
I have now hit a scripting road block in my beginner coding journey & for the last two days haven’t been able to progress. I’ve been trying to get my player & enemy script to talk to each other. I will provide as much info as I can & I am hoping someone can give me some help.
I am trying to make a 2D game. I have 3 scenes (main, player and enemy). Each scene has their own parent node, children & script. My main scene is where everything happens (play space). In my main scene I have added the player & enemy. The player and enemy nodes contain: Character2D, Sprite2D, CollisionShape2D, Area2D as well as a collisionShape2D linked to that Area2D, and their own script.
I have giving my player input controls, managed to get the enemy to randomly spawn along the y axis and travel across the x axis at speeds determined by their size. I can make the player respawn any sized enemy & increase the players scale by 0.01 by collision but that is as far as I can get. I can’t seem to get the player or enemy script to talk to each other and determine scale as a factor when the collide function happens. I also think that because the player & enemy scales are constantly changing this might trip me up even more as there won’t be a consistent scale. Through my googling I think this is where signals come into play but I’m really struggling to wrap my head around signals & their interaction with player/enemy collisions. The more I read into it the more confused I get.
I have added a (_on_area_2d_body_entered) signal to both the player and enemy. As I think this signal is best suited for what I would like to achieve but I am happy to try another signal if there is another best suited for the job. From here I assume I give the player & enemy script to each emit a signal regarding their scale information, then in the main scene script is where I receive those signals to complete the script?
My lame understanding example: player send signal to main scene telling it “this is my information and code” & enemy does the same. Then main scene receives each signal & says “ok, I have both your information, so I can have you interact with each other on my scene & determine what happens when you both collide into each other”.
Please keep in mind I am quite new to Godot (started using it 4 days ago). I have uploaded a screenshot of my mainscene layout to give you an idea how everything is set out. My player & enemy are in their own groups also.
Any help would be wonderful.
TLDR: The player & enemy scale is constantly changing & I would like my player & enemy to know each others scale when colliding to determine what happens depending on that scale. eg: player eats smaller enemy & grows by 0.01 & enemy respawns otherwise larger enemy eats player & player respawns to original scale.