xyz I don't really understand it that well, but it seems it works perfectly, thank you!
- Edited
So I have a little area that prompts with some text that tells you which X amount of 2 different items you need.
For example:
I store the items (materials) I pick up in a Global singleton, like this:
And the area that tells you what items you need looks like this:
But I'm struggling to make this work, I don't know how to make the Material 1 and Material 2 from the dropdown list of the building area to be the same items you need, or explained in a different way, I don't know how to use my variables stored in my Global singleton be Material 1 and Material 2.
This is how it looks so far, the "Global.materialneeded" variable obviously doesn't exist:
Any tips to achieve this? or am I trying to do it simple when it's harder than this?
Also right now I can only have 2 materials required, I don't think this system would work if I wanted to ask for a third material...I tried to "compare the names" of the Global variables with the material 1 and 2 names, but that didn't end well.
LoipesMas Your solution worked! had to change some things from my code and now it keeps chopping down trees without having to re-enter the area. Thank you
- Edited
I got this little game, the player can walk towards a tree, get inside its area2d to be able to chop it down.
But if there's another tree colliding with the player at the same time, when I chop one tree down (queue_frees it), I can't chop the other tree until I walk out of the area and then walk inside the area again.How could I make it so it doesn't matter if an area dissapears? If the player is still inside an area, I want it to still be able to chop the other tree down.
This is the player's script:
This is how the scene looks, with two trees overlapping and the player touching both tree's areas:
(The red areas of the trees are the ones allowing the player to chop them down)
(The little green/yellow area of the player is the one that detects the red area of trees)And this is how the _process func of the player looks like:
I understand the problem, I just don't know how to solve it. I saw something about "overlapping_areas()" but I don't know how to use it properly for this case.
- Edited
Alright finally did it with more help too, this is how it looks now (also I forgot to mention I have every node scaled to 3...):
It finally works! yahoo
- Edited
I don't understand much, honestly, this is what I've done and gotten so far (still doesn't work, no tile gets deleted and nothing happens at all)
The yellow area of the player is the mining area.
Console prints when touching a few tiles:
Something I noticed is sometimes I get a different "tile" result depending from where the area touches the tile, like this one, even if the tile is the same one:
Also the coords are always the same? This is how my tilemap looks:
I'm sorry I don't really understand much of what I'm doing, need more help please!
- Edited
I want to make a classic mining a cave mechanic in a 2D game, where the player can detect a tile in front of them and press a key to delete that tile so it looks like you mined it.
But it seems complicated enough for me to not understand how to do it, so please let me know how you'd do it!I'm guessing I need either an area2D or a raycast2D to detect the tile, and I've watched a few videos about tiles, but I just can't get it to work.
I don't know how to get the tile id, the coords, or whatever you need to erase the specific tile you're detecting! Help! (Using Godot 4 right now)It also doesn't help that all tutorials I've watched do this by using the mouse. I don't want to use the mouse for this.
Also some functions have been changed/removed for Godot 4, like world_to_map or cellv, so I have no idea!This did it! I feel like this is a very bad and cheap way to do it, but I don't know a better way right now!
- Edited
It looks like this now, which I'm guessing it works, but the sprites are always the default value set in the editor, in this case 1:
As you can see, all three npcs look the exact same (that's frame 1, the value set in the Sprite node itself in the editor), but at least ONE of them should look different, and the portrait to the right would be the corresponding sprite:
What could be going wrong?
My guess is that the onready var line of code (in every npc's script) is the one overwriting the changes made in the level script?
- Edited
Sorry for the weird title, I want to have a scene with many npcs, each of them get a random sprite frame when the scene starts, but I want one or two of the npcs to have a different sprite instead.
I don't mind normal npcs repeating sprites I guess, but I want the vip one(s) to be the different one(s), how could I do that?I have an array of npcs, an array that saves the vip npc, and I have the random sprite frame they get once the scene starts saved in variables, let's say there's 5 sprite frames in total to choose and they get a random one from 1 to 5 with a rand_range().
But I want to pick a different number for the vip npc that's not any of the numbers that already got picked, is there an easy way to do this?
I've tried a few things but no matter what, all their frames default to the one I choose in the editor itself.. by default the frame is 1, because I use frame 0 for their dead sprite.This is the level script that picks which npc is the vip, and the sprite frames:
This is the npcs' script:
Thank you!!
thanks for the replies! i tried them but they didn't work 100% as i wanted, although the ideas were pretty nice.
I ended up doing it like this with help!!:it works now!
I'd like to get my username "LadyRuru" changed, as I don't wish to use it anymore, is there a way to get it changed? please.
- Edited
So X number of npcs get added to the scene when the game opens, and a random number rolls to determine which npc gets to be the "VIP", the "Target" or whatever you may call it.
Being the "VIP" means being inside an array, and if you kill it, you win, earn money and whatever.
The npcs are multiple Kinematicbody2Ds that are identical but their sprite and if they're VIP or not get to be random, that's it.But I want only one of them to be the "VIP" npc, and if more than one get to be in the array, I want to remove as many elements as necessary, leaving only 1 element inside.
I've tried this, but it doesn't work as I want it to:
#Global.npcTarget is one VIP npc #Global.numberofTargets counts how many VIPs got added when game started if Global.npcTarget.size() > 1: for i in range(Global.npcTarget.size() - 1, -1, -1): Global.npcTarget.remove(i) Global.numberofTargets -= 1 print("Removed an element, now array has: ", Global.npcTarget) print("Num of Targets: ", Global.numberofTargets)
That code is in a _process function, and this code is the one that adds the VIPs:
func _ready(): randomize() var randNumber = int(rand_range(1,5)) $Sprite.frame = int(rand_range(1,5)) print(randNumber) if randNumber == 3: istheTarget = true Global.npcTarget.append(self) Global.targetFrame = $Sprite.frame Global.numberofTargets += 1 print(self, " is Target!") else: print(self, " is not target...")
it's very messy, I just don't know how to code something like this properly!
This ends up with the game having multiple VIPs (Targets) sometimes, and sometimes with ZERO VIPs,
and also if there are multiple VIPs and one of them gets erased from the array, the variable "istheTarget" will remain TRUE, which will allow me to kill that npc and it will count as a VIP, I don't want that either...I'm also doing this to match a Sprite portrait frame with the corresponding sprite frame of the VIP npc.
Please, help me! I suck at arrays </3
Also some pictures of my code, the last one being a global singleton:
This one adds the VIP, and the code is inside the NPCs' script:
This one removes VIPs until there's only one of them, although sometimes it will remove ALL of them... and the code is inside the Level itself's script:
This is the global singleton:
The result of all this being sometimes this:
- Edited
@cybereality said: You can pass null as the third parameter and it will use the current position.
Thanks to both of you it kind of works now. The closer the player is to the spells, the slower they will move towards the player, and the further the player is, the faster the spells will move.
Also, because I'm using the idea of hiding the sprites that have no area2d or anything, and then moving the Node2Ds that have the area2ds, I never reset their positions to where they should be to go back to follow the path2d around the enemy, so on the next attack, they will move from the last position they ended up, and not from their initial position (the one inside the pathfollow2d). Getting a bit complicated haha
- Edited
@cybereality said: You wouldn't usually use AnimationPlayer for dynamic animation. You would use a Tween. Most likely the easiest thing is to hide the animated spell (set visible to false) and then spawn an identical Sprite in the same position and use a Tween with code to move it where you like.
That works so much better, thank you! My only problem now is that the spells move very far away, they don't move to where the player currently is. Am I using the Tween wrong?
- Edited
I'm trying to make some wizard enemy that has 3 spells (Node2Ds) around it following a path with PathFollow2D.
My problem is that, when it attacks, I want each of the spells go towards the player's position one by one, first the circle, then the square and then the triangle. (I don't want them to FOLLOW the player, just go to where the player was).
I tried using an animation player to make their moving animation and THEN changing their destination to be the player's global position changing one of the key values of the animation, but it's not working as expected.
The direction the 3 spells move, x value being 120
With the script right now, the circle spell moves way too fast and it doesn't go to where the player is, probably because the animation is making things worse.
I'm also trying the state machine and it kinda works. This is what my project looks like right now, lot of screenshots sorry:
First part of the code
Last part of the code
The state machine
And what the attack animation does (it makes the animatedsprite change to "attacking animation" and calls attack()
I'm sorry if it's a bit confusing or if I'm asking too much, I just want to know if there's an easy way to make Node2Ds move to an specified position and at a lower speed. I'm probably making things harder by using animations... I guess this would be easier if I made the spells separate scenes instead of creating them inside the enemy itself, so then I instance them one by one with a set speed or something... I'm not sure
This is how the problem looks like, everything is broken:
Thank you for the help!
Nevermind, guess I got it working by just dragging the enemyArea and the detectAre INSIDE the Sprite and then simply animation the Sprite node. A bit weird but it works as intended!
I want to make a worm enemy that comes out of the ground and then goes back inside. I'm using a KinematicBody2D although I could use an Area2D but the problem is the same. I tried animating its position and then using the "play_backwards" function in the script, but as this has been asked many times iirc...
It will move the node's position starting from 0,0, and that's not what I want. I want it to move up and down in the position I place the enemy in the editor. Is there a way to do that? I also tried animating the SPRITE node but that's not useful if I can't move the Area2D to detect collisions...
Nevermind, got help and finally works now!
I still don't know how to make it so I can teleport to a different Level scene and its specific Warp node, but for now that will do I guess
make sure you set the Collisions of the tileset and the player properly! the Layers and the Masks parts specifically.