View Full Version : Automatically shooting turret
12-04-2008, 02:22 PM
I am trying to animate a turret for a big spaceship. I want it to emit a particle, whenever it fires.
For this I have linked a emitter-object to the barrel. In PFlow I use a Position Object Operator to birth a particle on the emitter and a Speed Test to determine when the bullet is spawned.
Now the emitter-particle is in a new event and doesn't follow the emitter-object anymore, so any consequtive shot doesn't spawn a bullet.
I created a closed loop with an Age Test to send the emitter-particle back to the Position Object Operator.
Everything works fine, untill I add a second turret. The problem is, that the emitter-particles are not distributed equally to the emitter-objects and when they went through the closed loop, they often changed thier position, so when one turret fires twice in a row, the second shot doesn't emit a bullet, because the emitter-particle has moved to the emitter-object of the second turret.
The only solution I can think of, is creating a separate Flow for each turret, but since the ship will have many many turrets (about 30-50, not sure yet) I would prefer doing it within one Flow.
Any help would be highly appreciated.
12-04-2008, 09:21 PM
That sounds like a pretty cool approach.
Off the bat I would say you going to have to create multiple emitters. It would be the easiest way although a little more time consuming. You'll get a lot more control out of it.
You could try adding a script/box#3 operator that reads counts the amount of current particles and there position at the end of the event and add another script/box#3 test in the loop that reads/sets the position looks for a change amount, if so then passes the spawn out of the loop. Just an idea its hard to say.
Something else, maybe try locking the first born speed test particles to the emitter with the pos. obj Lock On Emitter.
12-04-2008, 11:13 PM
Unfortunately I don't have Box#3 and my scripting skills are quite low.
I also tried to link the spawned particle to the emitter and use it as emitter for the next round, but that lead to the same problem as before.
Guess I have to dive into the Max Script Reference and lern writing my own Spawn by Speed Test...
Update: I have found some kind of flawed alternative: Using a Spawn Test with "by travel distance" instead of the Speed Test + closed loop. The drawback is that the ship cannot move during the firefight (since that would also spawn Bullets)...
12-05-2008, 01:44 AM
After a quick bit of thinking came up with this. I was taking it a little to...well.. anyway
Here's a quick proof of concept. Super simple using a collision spawn and a deflector to generate the gunfire. Just add a deflector in front of every turret and there you go you ship can be flying all over the place. :)
12-05-2008, 02:10 AM
Thanks man, I'll have a look at it.
But meanwhile I wrote me some little script that works. It was simpler than I thought. It is essentially a Spawn by Speed Test
on ChannelsUsed pCont do
pCont.useSpeed = true
pCont.usePosition = true
on Init pCont do
on Proceed pCont do
count = pCont.NumParticles()
for i in 1 to count do
pCont.particleIndex = i
if length(pCont.ParticleSpeed) > 0.05 then
pos = pCont.ParticlePosition
spd = pCont.ParticleSpeed
pCont.particleIndex = pCont.NumParticles()
pCont.ParticlePosition = pos
pCont.ParticleSpeed = spd
pCont.particleTestStatus = true
on Release pCont do
As long as the Ship doesnt fly too fast it should work. (It does when it stands still...)
Attached is a screen of my Flow. It also got quite simple with the script.
Update: Thank you very much JohnnyRandom for the idea with the deflector :bowdown: . It works like a charm. I think it is even better than my script, since it has no limitation on the ship's movement. (It was still a nice exercise to write it...maybe I need it some time...)
Off to bed now. It's 3:30 AM here... :surprised
12-05-2008, 02:10 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.