[Closed] Dynamic parenting
Hello Guys sorry to come back with more questions but I`ve come against a problem I dont know how to overcome with the script controller,
In my scene I have 2 objects called Dummy01 and Dummy02 and a Custom Attribute spinner, Dummy02 is travelling around the scene.
I have a position script on Dummy01 and the script is tells Dummy01 that when the spinner value is 1 then its position is == Dummy02,
The bit I am having a problem with is how do I explain to the script controller “At spinner value Zero don’t follow Dummy2 and stay exactly where you are”.
The spinner itself will be driven by the reactor controller.
Thanks for reading
Cheers
Dan
Hi Dan,
It takes a little while to get used to script controllers but their potential use is limitless. I think I understand your question. You want to have a custom attribute that serves as an on/off switch. When the switch is turned on, Dummy01 has the same position as Dummy02 and when the switch is turned off, Dummy01 stays in its current position and does not share Dummy02s position anymore.
Based on the assumption, you will need 4 custom attributes for Dummy02 and Dummy01 will need 2 scripted positions controllers and 2 scripted weight controllers.
For Dummy02:
- create 4 custom attributes:
[ul]
[li]onOff range:[0,1][/li][li]xPos range:[-2500.0,2500.0] *[/li][li]yPos range:[-2500.0,2500.0] *[/li][li]zPos range:[-2500.0,2500.0] * [/li][/ul]
*(increase min/max value for your case)
For Dummy01:
[ul]
[li]Create a Position List in Track View[/li][li]In the Position_XYZ spot , assign to Position Script[/li][li]In the Available spot, assign another Position Script[/li][li]You will now have two spots in the Weights portion[/li][li]In each spot, assign a Linear Script[/li][li]For the first Position Script, use this code:[/li][list]
[li]$Dummy02.Custom_Attributes.xPos = $Dummy02.pos.x[/li][li]$Dummy02.Custom_Attributes.yPos = $Dummy02.pos.y[/li][li]$Dummy02.Custom_Attributes.zPos = $Dummy02.pos.z[/li][li]$Dummy02.pos[/li][/ul]
[li]For the second Position Script, use this code:[/li]
[ul]
[li]newXPos = $Dummy02.Custom_Attributes.xPos[/li][li]newYPos = $Dummy02.Custom_Attributes.yPos[/li][li]newZPos = $Dummy02.Custom_Attributes.zPos [/li][li]newPos =[newXPos,newYPos,newZPos][/li][/ul]
[li]For the first Linear Weights Script, use this code:[/li]
[ul]
[li]if $Dummy02.Custom_Attributes.onOff > 0.0 then ([/li][li]weightVal = 1 )[/li][li]else([/li][li]weightVal = 0[/li][li])[/li][/ul]
[li]For the second Linear Weights Scripts, use this code:[/li]
[ul]
[li]if $Dummy02.Custom_Attributes.onOff > 0.0 then ([/li][li]weightVal = 0 )[/li][li]else([/li][li]weightVal = 1[/li][li])[/li][/ul]
[/list]
So, you always need to record the current position of Dummy02 because you do not want Dummy01 to pop back to its original position when the onOff switch is off. Now, if you move Dummy02 and animate the onOff switch, you will see Dummy01 either staying in its current position or having the same position as Dummy02.
If you need a file with this code, just let me know and I will find a spot for it on my server so I can add a link to it.
Hope this helps some.
Bret
oh man, this sounds great. Just read your reply so I haven’t had time to recreate your methods but it seems like you have a good solution, though as you can probably tell I`m a bit of a novice with this side of max. So I was wondering if I could take you up on your offer to have a file that works which I could dissect. Though only if you have time as I don’t want to cause you any inconvenience.
Thanks for your help much appreciated.
Dan
Glad to be of help. The best way to learn MAXScript is to come up with a problem and try to find a scripting solution.
Good luck!
Bret