How to reduce the random generation frequency ?
Asked Answered
E

6

0

Hello, I'm a beginner on Godot and I'm trying to generate arrows on my scene that will kill the player. But too many of them are generated and and it doesn't work well at all. Any idea on why's that ?
(I also tried with a timer but i think I'm doing it wrong 😅)
/

Epergne answered 24/1 at 22:57 Comment(0)
P
0

How are you generating the arrows? I don't see that in your code.

Perice answered 25/1 at 0:47 Comment(0)
D
0

no one can help you adjust your arrow spawn rate until we see the code or nodes that spawn the arrows, your screenshot of code only has it for the arrow itself.
are you spawning it with a timer? if so it's as simple as increasing the timer's time between when it fires.

more explicitly we want to see the level 1 script and level 1 layout, I'm betting that's where the arrow spawning stuff is

Dovetail answered 25/1 at 0:47 Comment(0)
E
0

Dovetail Yes, sorry for the late reply.

I've figure something out with Youtube tutorials but now I have the opposite problem, too few arrows are spawning in! I've tried shorten the timer countdown but it doesn't seems to work. I can leave it that way but the game really isn't hard at all like the rage game I wanted to make.
Any advise on what else could I tweak on ?

Epergne answered 27/1 at 21:49 Comment(0)
P
0

Why are you calling _ready() inside _process()? That's calling _ready() every few milliseconds. _ready() is intended to do one-time initialization when a node is added to the scene tree.

Epergne too few arrows are spawning in

Please be more specific. At what rate do you want arrows to be generated? Compared to that, how exactly is it behaving now?

Perice answered 27/1 at 22:11 Comment(0)
P
0

The timer is initially 0.2, which calls the timeout function. The code decrements it and reduces the overall timeout so it will call the timeout quicker, then reducing the wait time even more.

Just remove the $Timer.wait_time -= 0.001 for now, adjust the wait time in the editor. If you do want this behaviour, getting faster over time, you likely want extra logic to control minimum values.

Pub answered 28/1 at 11:8 Comment(0)
P
0

You could also incorporate a limit to how many arrows are on-screen at once and have a separate variable track how many arrows are currently "live" (an easy way would be to put your arrows in a group called "arrows" then track that). Then attach a VisibilityNotifier2D to free the object when it is off screen. Arrows don't spawn when you hit a certain amount and I'd use a bool to "toggle" that. Then just check to see if that flag is toggled before you spawn (use get_parent()) if necessary, don't know how your sceneTree looks). If _spawnFlag is true, arrows can spawn. When it isn't, they don't and that bool flips anytime the arrows are at the max total.

Someone here can probably do this more efficiently. While I have this being checked in _process(delta), you probably don't have to do it every frame. Just check for it every time an arrow spawns by connecting it to a signal.

For example:

var _arrowsCurrent : int = 0
export var _arrowsMaximum : int = 10
var _spawnFlag : bool = true


func _process(delta):
     _arrowsCurrent = int((get_tree().get_nodes_in_group("arrows")).size())-1
     if _arrowsCurrent >= _arrowsMax:
          _spawnFlag = false
     else:
          _spawnFlag = true
Pallaton answered 28/1 at 18:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.