[Closed] Self references in Script Controllers?
Hi, guys! This might have been asked here, but I could not find a thread related to that. So my apologizes in advance if this has been asked before
The thing is that I’m starting to dive into technical things very unknown for me (it’s nice to battle challenges that are quite impossible!). So I’m trying to get some real time dynamics in MAX using the Verlet Integration algorithms. For achieving that, I need to reference the object previous position in the script controller of that object, and as you all may know that provoques a ‘illegal self reference’ error message.
I decided to go other way: two points, one is the driver (P1), the other is the driven (with the script controller on it, P2). Another point is position-constrained to the driven (P3), and an expose-transform measures the distance between P1 and P3, and uses this distance for the script controller in P2.
So if you have arrived here (I hope I’m explaining this as clear as it should be), you should know that when I run the script, the behaviour that is supposed to take P2… is beeing passed to P3! And P2 decides to go for an offset walk (double transform)… but the system, although in a crappy way… well, it works
So after this long and boring explanation, I think that if I could reference the position of P2 under its script controller, everything would be better. And since it does not seem to work in a direct way, can you point me to some workaround or way to do this? It’d be very appreciated
I’ll post a video as soon as possible.
I’m not sure I understood right, so correct me if I’m wrong, but you want to know the position of the point in which it was a frame before so that you can derive from it?
If so, use
at time
clause in order to get the value at a given time in scene.
Hope it helps, cheers…
The at time sounds godo to me also, but you may also want to look into weak references, although not sure if they are the answer here. Anyway, Paul Neale has a good article on his site: http://paulneale.com/tutorials/Scripting/weakReferences/weakReferences.htm
Thanks, dudes! But I think I was not clear. So, to resume, basically I want to use the clause ‘$Point2.pos’ inside its position controller without getting any error. From what I’ve read, this seems impossible… but there should be a way do it…
And thanks for the link: I’ll take a look
By the way, here you can see how it is going:
Thanks!
You can’t make a reference to a .position but you could reference a position controller of the same object and then do whatever you want to the final value of the position.
Since positions are summed you will have to cancel the contribution of the position XYZ controller or put its weight to 0 in the list controller like in the example attached(3dsmax 9), where a Teapot has a lag of 10 frames in its own position
Also, if you have more than one position controller in the list your final one will have to sum all of their contributions manually in the script and put all their weights to 0 (or cancel their contribution in the script)
This is just a tip I got from Camilo Póveda
PD:But now that I think it won’t work in the way you want since this will always work from keyframed positions, not the ones calculated from your verlet integrator.
I think max is not suited well to do this in real time and you will need either to loop all the frames until the actual one(becoming in a frame-range dependent solver…)
or a calculation preprocess to cache the resulting values in a structure the script have direct access
hi iker,
if i understand what you are trying to do you should just store the previous position in a variable in the script controller
so example…
use a varialbe prevPos set to a constant of [0,0,0],
at the end of the script use this.setConstant “prevPos” Pos
with pos being the end result of the script.
i have already done stuff with verlet integration at home so if you need a hand gime a mail or pm…
mark
nice result man !
i´m having troubles to understand VERLET and how to implement it in MAXscript…
please,
tell more about it and if possible share the formula.
ps :
http://www.d3coy.com/gallery.htm
http://www.d3coy.com/downloads/Realtime%20Maxscripted%20Physics.rar
http://d3coy.cgsociety.org/about/
James Cleaveland
Borja and Mank, thanks for your feedback, dudes! I’m quite busy with other things at the moment, so no Verlet fun for me at home until a few days.
Renato, the system is not stable and not usable in production at the moment. I used the formulas that are written in some pages… linked in your blog! In addition, to full-understand the formulas I used some actionscripts from Flash and some Java scripts too. There you can guess how to interpret the formulas By the way, I used the ‘constraint’ one.
So since the scene is quite “buggy” and there are more than two objects and one script, it is not very useful to make it public. If you want, I can send it to you, anyway.