#Spawning a collision box upon casting a spell (and then despawning it too I guess)

1 messages · Page 1 of 1 (latest)

drifting summit
#

I have my spell system complete in code, and I made a collision box for where I want that area to be, but I'm not entirely sure how to go about having the "cast" command actually spawn that area in front of the player for the specified duration, size, etc.

    #Check is spell is empty
    if queue_counter == 0:
        print("Your spell is empty!")
    #If spell is full, cast
    elif queue_counter == 3:
        queue_counter = 0
        print()
        return(cast_queue)
    else: print("Your spell isn't full!")```

cast_queue is the full list of all variables of an assembled spell including the name, duration, and size of the collisionbox I want to spawn.  What should I put in place of my print+return script to actually call on the asset I made?
sterile cedar
#

First, how you're asking to do it.

You can create any godot node of class Foo with Foo.new() (so: var area := Area3D.new()).
It's not in the tree until you put it into the tree; you're calling this from some class MagicMain so it could just add_child(area).
But MagicMain isn't a Node3D (and not the targeting reticule or whatever either) so it'll have the wrong positioning. You can fix that! area.position = ... (for whatever position you want it to have).
You might want to make these effects children of the scene or something too, instead of MagicMain. YMMV

You are already collecting information about targeting iiuc; also collect a position into which you want it to go.

#

Second, how I would do it. Very similar BUT. I would have each spell be a scene (.tscn file). You can (pre?)var my_spell := load("my_spell.tscn") as PackedScene or @export my_spell: PackedScene.

You can my_spell.instantiate() that object. From there, the instructions take up from above wrt add_child and setting params on the returned spell

drifting summit
#

I absolutely see the value of option 2, but the premise is making a handful of elemental magic types ("chapters") with components that you assemble, so there are way way more possible spells than I oughta be hard coding 😅 I'll try your solution 1 this weekend! Thank you for the tips and a good source of more stuff I can research!

sterile cedar
#

definitely can still make the individual parts subscenes that self assemble. But yeah, you're going to need to glue stuff together, that makes sense!