I have an event that spawns a physics projectile, then checks it for collisions and when it hits something calls another event and removes the projectile. However, i need to be able to have more than one of this projectiles at once, but it can only check for collisions on the last spawned object.
Is there a way of doing this other than copying the event for every projectile that can exist at once and calling a different event for each subsequent projectile?
The way that I would do it is to add a trait to the object that you spawn that handles the collision logic. I like try to organize the logic and traits so that each object mostly looks out for itself. So if I have a bullet, I give that bullet a “Bullet” trait that handles its expire time, its collisions, and its movement speed. I also have a gun, and I give that gun a “Gun” trait, that handles listening for trigger pulls and spawning bullet objects. If the “bullet” object that you spawn has the “Bullet” trait applied to it, then every spawned bullet will also have that trait and will therefore behave like a bullet, which disappears and spawns an explosion on contact.
I see, that’s just what i needed, thanks again. I’ll take a deeper look at how traits work.
How can i refer a node to the spawned object when it’s on another node tree? If i refer to the original then it’s only applied to it
Sorry, I don’t understand exactly what you mean. Could you elaborate a little?
Let’s say i want to use a set velocity node to get the spawned object moving, for example.
What should i connect to the set velocity object input?
Here is a screenshot of my Bullet node tree:
This trait simply removes the bullet when it hits something, and it moves the bullet at a speed of 100 in the bullets look direction ( local positive Y direction ).
For my gun I have the following trait:
This just spawns the bullet and sets its transform to the transform of the gun ( this should probably be the transform of an empty in front of the gun instead ). When the bullet is spawned it will already be pointing the the same direction of the gun, and the “Bullet” trait will handle setting its velocity to 100 units/second in the direction it is pointing.
The ‘Self’ node is what i was after, i missed it since i was finding for something with Object in the name. This clears that out.
BTW If you leave any object selection field in a node blank, it will default to self. That can help make node trees a little more readable sometimes.