PDA

View Full Version : Find Target -> Particles


krifos
09-13-2008, 12:47 AM
Hi,

I'm trying to use find target to target other particles in another particle system. I've created an asteroid-system using PF, and I want to blow them up later with another particle system that will supply rockets that will use find target.

However, I'm not able to do so - and I've been googling around, and it seems like I would need some kind of script to "convert" the particle system to mesh so that they can be targeted.

Does anyone know about an easier way, or know about a script that does what I need?

ADamiani
09-13-2008, 01:24 AM
Right! I'm pretty sure you can't do it while the other system is still in pflow, unless you have Box #3 (or so I am told). However, pflow baker can help you mesh out your animation: http://www.scriptspot.com/3ds-max/pflow-baker

That should allow you to make them targets.

Now, this doesn't solve your whole problem, because you need them to disappear/break up when they're hit. This is going to take some scripting, and I'm not 100% sure how I'd go about it.

I suppose, in theory, if you assigned each mesh a separate U-OmniFlector, you might be able to add a script operator (after a collision test) to the missiles to hide the base object of the deflector they hit?

Bobo
09-13-2008, 04:34 AM
Hi,

I'm trying to use find target to target other particles in another particle system. I've created an asteroid-system using PF, and I want to blow them up later with another particle system that will supply rockets that will use find target.

However, I'm not able to do so - and I've been googling around, and it seems like I would need some kind of script to "convert" the particle system to mesh so that they can be targeted.

Does anyone know about an easier way, or know about a script that does what I need?

This is really not necessary, because a Script Operator in PFlow can write data into the Script Vector channel of the particle system and "feed" it with targets from another particle system.

See this thread and the example I posted:
http://forums.cgsociety.org/showthread.php?f=206&t=659462

krifos
09-13-2008, 03:54 PM
Thanks both, trying out the Bobo-script now, and I've made the rockets delete after finding their target.

However, the rockets doesn't seem to find their targets properly. I have five rockets that are heading towards five different asteroids, but they just pass right next to them, and they don't delete themselves (naturally since they only pass right next to them)

I've attached my scene-file (Design 2009) if anyone bothers to have a quick look.

Bobo
09-13-2008, 04:05 PM
Haven't looked at the file, but keep in mind that FindTarget is not absolute, it is just a force operator. So it drives your rocket to go in the general direction, and the test is based on a proximity threshold value - you might want to increase it to get a "hit" if you are sending out the rockets to a Delete event.

Also note that the Find Target has two useful modes - Control By Speed and Control By Time. In the Control By Time, you can define how long should it take to reach the target, and the speed will be set accordingly. I find this method to be more solid when targeting moving objects/particles. The Control By Speed is very dependent on the Speed/Acceleration Limits and might never reach the target depending on how fast it moves or changes directions.

Play with the settings and you might find the best control method for your case.

krifos
09-13-2008, 04:18 PM
Thanks for quick reply :)

Find Targets works accurately (or more at least) when I've made random asteroids myself (as mesh) and scattered about. It just doesn't work properly now using this script operator to target the particles.

See the attached screenshot, orange is emitter, green is asteroids (particles), blue is rockets and red is their trails. As you can see, they head in roughishly the correct direction, but they miss by quite a lot. (the distance between emitter and particles is greater than it looks btw)

Since they don't do when I've manually placed the asteroids there (without PF), there has to be some tweaking to do with the script I'm thinking? If I could have them target the centre of the objects somehow (as they do outside PF).

Sorry if I explained myself poorly :blush:

JonathanFreisler
09-13-2008, 04:27 PM
i downloaded the attachment, but there doesn't seem to be anything in it? could just be me (why am i still using Google chrome, lol)

If the asteroids are moving, it could be finding them at there initial state? and not calculating there movement? Not sure without checking the file out.

krifos
09-13-2008, 04:30 PM
Should be working, I just downloaded the zip and opened the max-file. Try downloading with FF or IE or Opera ;)

I've disabled the spin-operator so the asteroids are not moving and not rotating, but it still happens.

JonathanFreisler
09-13-2008, 05:06 PM
IE worked fine lol. Thanks google. If you turn follow target animation off they hit the target 100%... but that doesn't help you terribly.

Bobo
09-13-2008, 05:18 PM
Thanks for quick reply :)

Find Targets works accurately (or more at least) when I've made random asteroids myself (as mesh) and scattered about. It just doesn't work properly now using this script operator to target the particles.

See the attached screenshot, orange is emitter, green is asteroids (particles), blue is rockets and red is their trails. As you can see, they head in roughishly the correct direction, but they miss by quite a lot. (the distance between emitter and particles is greater than it looks btw)

Since they don't do when I've manually placed the asteroids there (without PF), there has to be some tweaking to do with the script I'm thinking? If I could have them target the centre of the objects somehow (as they do outside PF).

Sorry if I explained myself poorly :blush:

Bummer. Don't have 2009 installed at home.
So let's try to solve this without looking at the file, otherwise I have to drive to the office on a Saturday ;)

Chances are the data in the Script Vector Channel is off for some reason.
First of all, I assume the asteroid particles are moving. Second, I assume the Script Operator is running on each frame, constantly updating the positions of the moving asteroids to the rockets' Find Target. Does this sound right?
Now, you have the asteroids as meshes. Can you confirm that the Asteroid Meshes' Pivot Points are centered correctly? Does it look the same when using a simple Shape Operator or Display set to Tick? Just trying to exclude the case where the Shape's Mesh has a Pivot outside of the geometry and the particle appears offset in PFlow, while being somewhere else completely. (I know you are smarter than that. but just checking).

Also, is the Find Target set to Icon or Mesh Objects? If it is set to Mesh Objects and something is picked in the list, all Script Vector positions are interpreted as local coordinates relatively to the mesh instead of world coordinates, which could introduce quite an offset...

JonathanFreisler
09-13-2008, 05:34 PM
ok, well i managed to get the particles to find there target, and then to go to there next event,

for some reason disabling 'follow target animation' worked with countering the offset. But that doesn't help if your asteroids will be drifting.

hehe bobo, that was the first thing i checked, the pivot :P The asteroids are not moving at all, and there just idle doing nothing. But the offset with 'follow target animation' on sends them directly up on Z all in equal units if that makes sense.

krifos
09-13-2008, 05:44 PM
IE worked fine lol. Thanks google. If you turn follow target animation off they hit the target 100%... but that doesn't help you terribly.

I noticed that too now. However, if I want (and I do) the asteroids to move, it needs to be checked.


Bummer. Don't have 2009 installed at home.
So let's try to solve this without looking at the file, otherwise I have to drive to the office on a Saturday ;)

Lets pick the first option ;)


Chances are the data in the Script Vector Channel is off for some reason.
First of all, I assume the asteroid particles are moving.

I've tried both with moving and non-moving asteroids.

In the screenshot they are 100% still, and then it works by unchecking "follow animation", as JonathanFreisler mentioned. However, whenever "follow animation" is checked, it is somehow "offset" by a certain amount. I tried again to animate the asteroids, and the rockets still miss by the same amount - and if I play long enough, they turn around and chase past the asteroids in an endless loop (even after asteroids has stopped).

Second, I assume the Script Operator is running on each frame, constantly updating the positions of the moving asteroids to the rockets' Find Target. Does this sound right?

I guess, I'm no into scripting so I just copied the script which was in your example file, and replaced the events. :)


Now, you have the asteroids as meshes. Can you confirm that the Asteroid Meshes' Pivot Points are centered correctly? Does it look the same when using a simple Shape Operator or Display set to Tick? Just trying to exclude the case where the Shape's Mesh has a Pivot outside of the geometry and the particle appears offset in PFlow, while being somewhere else completely. (I know you are smarter than that. but just checking).

I'm smarter than that (I think) ;) But I checked again just to be sure, and changed display to ticks and boxes, and the rockets are still off. Pivot point should be centered to the mesh.



Also, is the Find Target set to Icon or Mesh Objects? If it is set to Mesh Objects and something is picked in the list, all Script Vector positions are interpreted as local coordinates relatively to the mesh instead of world coordinates, which could introduce quite an offset...


Yeah, it's set to icon. I tried to select Mesh Object, but then it only selected the original asteroid-mesh.

Bobo
09-13-2008, 05:53 PM
You are specifying the targets using a Script Operator via the Script Vector Channel.
Follow Target Animation MAKES NO SENSE if you don't target moving icons/meshes. If your Find Target does not specify meshes as targets, the target animation is provided by the Script Operator. On each frame the Script Vector Channel is updated with the current positions of the asteroids, and the Find Target has to target that.

krifos
09-13-2008, 06:03 PM
My asteroids are made up from a particle system. The asteroids are scattered within the volume of an object (in this case a box, but could also be a torus if I wanted to make an asteroid-belt).

To animate the asteroids, I'm using spin-operator (which shouldn't matter since they keep their pivot-points at the same spot), and then I'm animating the box up and down.

When I'm not using "follow target animation", the rockets go in the straight path as they do when the asteroids are not animated, and thus misses the animated asteroids.

When it's checked, they do follow them, but with the Z-axis offset as JonathanFreisler mentioned.

So if I understand you correctly, I'm not supposed to use the follow target animation at all? But how would they follow it then? Nothing seems to happen if it's not checked.

JonathanFreisler
09-13-2008, 06:10 PM
wait your animating the box up and down? the file i got didn't have keys on the box, problem might lie there. Id recommend not animating the box, and putting speed on them anyway.

bed time, its 3am.

Bobo
09-13-2008, 06:10 PM
Can you post a screenshot of the flow?
Are you positive the Script Operator updates the Find Target on every frame?
Can I also see the source code of the Script Operator?

krifos
09-13-2008, 06:27 PM
That makes sense since Bobo says I shouldn't use the follow target animation. However, that makes it very hard to make the asteroid-belt I was thinking about.

The plan was to use a torus as a scatter-area, and then animate the torus to rotate slightly, so that the belt rotated around a planet, while using a spin operator on the asteroids so that they would spin in different directions.

edit:

Didn't see your post before I replied, Bobo. I'll post a screenie in a min.

Sourcecode:
on ChannelsUsed pCont do
(
pCont.useVector = true
pCont.usePosition = true
)
on Init pCont do
(

)
on Proceed pCont do
(
count = pCont.NumParticles()
theOtherSystem = $PF_Asteroids
count2 = theOtherSystem.NumParticles()
minCount = amin #(count, count2)
for i in 1 to minCount do
(
pCont.particleIndex = i
theOtherSystem.particleIndex = i
pCont.particleVector = theOtherSystem.particlePosition
)
)
on Release pCont do
(

)

krifos
09-13-2008, 06:42 PM
It seems to be working (better) now ... I think the reason why it didn't update properly was because I used the "cache"-operator. It was set to update always, but it didn't ... Deleting it and the rockets are following the asteroids when I'm moving the box.


However, another problem occured - as soon as one of the rockets has hit it's target, some of the other rockets suddenly change theirs.

When the animation starts, all rockets has different target, but this is what happens in the end. The greens are asteroids, the reds are impacts.

Bobo
09-13-2008, 07:23 PM
However, another problem occured - as soon as one of the rockets has hit it's target, some of the other rockets suddenly change theirs.

When the animation starts, all rockets has different target, but this is what happens in the end. The greens are asteroids, the reds are impacts.

This was to be expected and can be fixed by using particleID instead of particleIndex.

What happens is this: The Script Operator asks how many targets are there in the other system. It also checks the count in the current event. Let's say you have 6 asteroids and 5 rockets. So it takes the lesser of the two and sends 5 rockets to 5 asteroids. Then a rocket, say #3, hits asteroid #3. The rocket is sent out and deleted, which gives you only 4 rockets in the event, 1,2,4 and 5. So suddenly rocket 4 has index 3 and 5 has index 4. Both have to change course and attack asteroids 3 and 4 instead of 4 and 5, because the count in the rockets container has changed.

But BornIDs are unique and given to particles at their birth. This makes them solid and unchanging. Thus, rocket 5 will always be rocket 5, even if its index is a different number because others have been deleted.

I have this case covered in my upcoming DVD about Scripting Particle Flow which I finished recording last month (but is awaiting the new download system of CG-Academy to get released). Here is the general idea:


on ChannelsUsed pCont do
(
pCont.useVector = true
)

on Init pCont do
(

)

on Proceed pCont do
(
count = pCont.NumParticles()
otherSystem = $PF_Asteroids
for i in 1 to count do
(
pCont.particleIndex = i --set the current rocket's index
local pIndex = 0 --init. a variable
--see if the other system has a particle with the same BornID as the current rocket ID:
otherSystem.hasParticleID pCont.particleID &pIndex
if pIndex > 0 do --if it does,
(
otherSystem.particleIndex = pIndex --set that asteroid as the current one
pCont.particleVector = otherSystem.particlePosition --and grab its position
)
)
)

on Release pCont do
(

)

As result, if you give birth to 5 rockets in the second system, they will get Born IDs from 1 to 5 and KEEP THEM. If you have 6 asteroids in the other system, they will also be numbered from 1 to 6. If you delete rocket with ID 3, asteroid 3 will never be attacked again because the rockets with IDs 4 and 5 will always attack asteroids with IDs 4 and 5, regardless of the order inside the event's container.

krifos
09-13-2008, 07:49 PM
Great, that worked :) Thanks so much for the help. That DVD of yours, what difficulty is it targeted at? Beginners / intermediate / experts etc?

I would love to learn som scripting, but somehow my brain is totally malfunctioning whenever it comes to anything that looks like programming / scripting. It's like watching a big question-mark.



edit: by the way, when I add a spawn-operator after the find target operator (in the same event), it messes up the script, all the rockets then change targets and some of the asteroids gets hit by multiple rockets.

I've added a spawn by travel so that the rockets will create smoke-effect, which works perfect when I'm not using the script-op.


In my current system it seems that the last 6 of the 10 rockets are sent directly to the center of world space (0,0,0). The first 4 is working as they should. This changes as I change the settings of the spawn by travel.



edit2: this seems to be related to that they are spawning one each 2nd frame. When they all spawn on the same frame, they all find their targets.



edit3: could this be because they generate new particles which gets IDs equal to the asteroid IDs? So when the first rocket spawn, it travels, generates new particles, and thus "spending" all the asteroid IDs.

Guess that could be fixed by offsetting all the ID's in the smoke-event with +1000 or so? Possible to do this via script?


edit: .flv-video: http://threedee.krifos.com/wp-content/uploads/2008/09/particletest2.zip

Bobo
09-13-2008, 08:28 PM
Great, that worked :) Thanks so much for the help. That DVD of yours, what difficulty is it targeted at? Beginners / intermediate / experts etc?

I would love to learn som scripting, but somehow my brain is totally malfunctioning whenever it comes to anything that looks like programming / scripting. It's like watching a big question-mark.




edit3: could this be because they generate new particles which gets IDs equal to the asteroid IDs? So when the first rocket spawn, it travels, generates new particles, and thus "spending" all the asteroid IDs.

Guess that could be fixed by offsetting all the ID's in the smoke-event with +1000 or so? Possible to do this via script?

The DVD will be targeted at people like you who know enough (intermediate level) PFlow but do not script much. From my point of view, it is an introduction into scripting Particle Flow, so it covers the basics. So I tried to keep it simple. Some math knowledge wouldn't hurt though. My "The Matrix:Explained" DVD would be a good companion.

Now to your problem - yes, you fire the rockets over multiple frames, and the trails of the first rocket "eat up" your IDs. The simplest solution would be to give birth to all your rockets on frame 0, then keep them invisible in the initial event and "fire" them by using an Age Test or something like that (a Script Test could also be used for more controlled firing). Thus, the rockets would always get the first N IDs, then you can spawn at your heart's will. Note that you can assign local Render operators to make particles invisible to the renderer in specific events.

The scripted alternative would be to use a Script Operator which initializes and increments a global "rocket launcher" counter and writes the rocket's number into its Script Integer channel. So instead of using the ID, you would be handing out the numbers and use the Script Integer channel of each particle inside the targeting Script Operator to decide which asteroid to attack. In addition, you could generate RANDOM values to store in the Script Integer channel based on the amount of asteroid particles, so you could have multiple rockets targeting the same asteroid (if desired), or any other special decisions like "never target asteroid 3" and so on. But this is more complicated and requires a bit of scripting knowledge, so try the first approach first...

krifos
09-13-2008, 09:24 PM
Great - Hope it's released soon :)


And, I'll go for the first approach and mess around to see if I can get the results I want :)

Thanks again for great help!

jigu
09-14-2008, 04:42 AM
Hi Bobo,

When will your DVD be released? Any chances to order it in advance?

Looking forward to it.

-Jignesh

Bobo
09-14-2008, 07:15 AM
Hi Bobo,

When will your DVD be released? Any chances to order it in advance?

Looking forward to it.

-Jignesh

It looks like it will be the first title by CG-Academy to be released as a downloadable tutorial. So in the beginning it won't be a DVD technically speaking. But you don't have to order in advance, as you would be able to buy it online and download it immediately the day it is released.

I finished "principal recording" in August. It needs to be edited into the final product which includes illustrations, transitions, menus and so on. So I cannot really tell when it will be out. It is mostly up to CG-Academy from now on. Keep your eyes open for posts by Chris Thomas...

jigu
09-14-2008, 09:35 AM
Thanks bobo for the information. I look forward to it.

Hope to get it this "Diwali"(Hindu's new year) in November... :)

Frutik
10-01-2008, 02:07 PM
see in november :-)

CGTalk Moderation
10-01-2008, 02:07 PM
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.