Notifications
Clear all

[Closed] Distance Script + Auto omni light creation

Alright I have two questions.

First: I just need to know how to create a simple distance script operator for a PFlow system such that when Object A and Object B are a certain distance from each other, Object B will fire an event. For a literal example, i’m creating a totally Pflow-driven space battle scene and I want an Object B (black ship) to shoot once it’s close enough to an Object A (white ship)…

Secondly. How would I script a PFlow event that would create an omni-light and automatically keyframe some intensity settings based on a Spawn event. Literal example being: When a ship shoots and it’s missile detonates, I want it to create an Omni light that will light up and decrease in intensity as such with the intensity of the explosion so that I don’t have to manually create and keyframe omni-lights for every PFlow-created explosion…

Hope you guys understood that and can help… Cheers!

47 Replies

For the second question, have it spawn one particle, then pass that to an event with a script operator and a delete (all). By running the script, it should create and key the light. I had mine create one particle at frame 10, and so it lit up my teapot from black starting at frame 10, then faded out again. You could extend this script (for example having one light for every particle) by parsing out the particle ID or something, if you so chose. I just have it quite restrictive because it keeps it from creating many duplicate lights.

on ChannelsUsed pCont do
(
	
)

on Init pCont do 
(

)

on Proceed pCont do 
(
if pCont.numparticles() == 1 do (
	try (
		x = execute("$explosionLight")
		select x
		max delete
	)
	catch (
	print "no object found"
	)
	x = omnilight name:"explosionLight" multiplier:0.0
	y = currentTime.frame
	animate on (
	at time (y-1) x.multiplier = 0.0
	at time y x.multiplier = 1.0
	at time (y+10) x.multiplier = 0.0
	print "Light Set"
	)
	)
)

on Release pCont do 
(
 
)

Not sure about the first question you asked though. Someone else will have to answer that.

As for the first question:

 [color=white]on[/color] ChannelsUsed pCont do
(
)
 
on Init pCont do
(
)
 
on Proceed pCont do
(
if (distance $obj1.pos $obj2.pos) < 100.0f then
[indent]for i = 1 to 8 do -- 8 is the spawn rate per frame 
[indent]pCont.AddParticle() 
[/indent][/indent]) 
 
on Release pCont do 
( 
)

This worked for me.

First of all, thanks to both of you for your help. However, I have gotten neither to really work so far and I’m having trouble figuring out how to integrate them. Hope i’m not too bold in asking if you guys wouldn’t mind posting some sort of max scene file with the scripts integrated so I know how you got your respective scripts to work? Thanks alot in advance!

The script I gave you was just the basic framework for a particle based event. To actually use it, I have taken it further and built a whole system around it. The script itself was modified slightly too (ie it now does as many lights as I want it too). At the moment, it is generating explosion style lights as particles strike some objects in the scene. Should be easily adaptable for your ship. To tweak the scene, I just change the pflow, delete all the generated lights from the scene (in case the next go round has less explosions), then hit update on the cache. Everything else is done for me. Life is good

http://ericburnett.homeip.net/explosions.max
http://ericburnett.homeip.net/explosions.mov

 Boa

Eric, in the help files it is stated that:

<LI>

<LI>You cannot excessively create objects during the evaluation of Particle Flow scripts (for example inside the on Proceed method).

<LI>

You cannot delete objects from inside a Particle Flow script. Note: There are techniques allowing the creation of a limited number of new objects as shown in the Fragmentation script example.

<LI>
And in a thread on the discreet board Oleg and Bobo discussed the creation of objects in Script Operators. Judging from there object creation should only be done in Init Handlers and preferably outside PFlow or in advance. The thread is called “Non-geometry objects as particles in pflow”. I don’t know why but I guess it is because the Script Handlers are called often. What do you think?

Boa

Which may explain why the omni lights, though ~50% successfully created, tend to either light up at the wrong time, or delete themselves, or, again, not create. Hmmm…

I can see why not to excessively create objects, but the script I made will only create a rigidly controlled amount…IE not excessive. And yeah, the proceed method is called very many times, so if it always created objects, the scene would run out of control very quickly. But I do not think there would be a problem doing it this way…every time one is recreated, the old one is deleted. You can NEVER have more objects than particles, and I ended up with way less.

I would be very interested in both where that is said in the manual and a link to that discussion. I am self taught scripting and pflow, so I really have no idea the best way for things to be done. I just go at it until it works :shrug:

Cryptite: Not sure what you mean. They delete themselves every time they are recreated, yes, but I just used a cache operator so that it would only happen as you want it too.

The lighting up at the wrong time would probably be from a previous creation affecting the new run. As I said before, I always delete all the lights before re-caching. And it also might look odd because of the way the scene is set up…some lights you cannot see are causing other objects to light up as well as the ones they are closest to. They also spawn where the particle was two frames ago, so that might throw you off.

About them not creating, there are three possible reasons. 1, they are hitting the objects but not the proxies, because I did not set up the scene very carefully. 2. Two should be created in the same frame. I am not sure if that works, will have to look into it. 3. The collision is not found. Might need to increase the sub-frame sampling.

And if you find that this script is flakey or something, don’t use it. I am still fairly new to this, so I am definitely not the best person to do things. I just try to help people with problems I do not know the answer too, figuring it out and teaching myself in the process.

Anyways, I look forward to hearing from both of you. I just did this for fun, so feel free to drop it and find a better solution. If you do find one though, let me know

I’m afraid that I don’t have a website to be able to send you any scenes, sorry :(.

 Boa

Eric, you’ll find the discussion on the discreet webboard (you’ll have to register):

http://support.discreet.com/webboard/wbpx.dll/~3dsmax

Search for a thread called “Non-geometry objects as particles in pflow”.

And for the help files: Look under MAXScript Extensions/MAXScript Extensions for Particle Flow/Limitations on using MAXScript with Particle Flow.

I’m sure no one wants to criticize you. It’s just discussing best/possible ways to achieve the intended result. I’m new to scripting myself and probably wouldn’t have “dared” to script the creation in the Proceed handler. It would be interesting to hear Oleg’s (the creator of PFlow) and Bobo’s opinion to your script.

Boa

Page 1 / 5