global proc xboxRocket() { setupXboxControlServer; setupXboxRocket; } global proc setupXboxRocket() { // Create the tube and connect the bend deformers string $rocket[] = `polyPipe -r 0.5 -h 8 -t 0.2 -sa 20 -sh 0 -sc 0 -ax 0 1 0 -cuv 1 -rcp 0 -ch 1`; addAttr -ln "rightTrigger" -at double -min -10 -max 1 -dv 0 $rocket[0]; setAttr -e -keyable true ($rocket[0]+".rightTrigger"); addAttr -ln "totalThrust" -at double -min -10 -max 10000 -dv 0 $rocket[0]; setAttr -e -keyable true ($rocket[0]+".totalThrust"); setAttr ($rocket[0]+".totalThrust") 1; addAttr -ln "thrustOutput" -at double -min -10 -max 1000000 -dv 0 $rocket[0]; setAttr -e -keyable true ($rocket[0]+".thrustOutput"); attachDeviceAttr -d "xenon" -ax "RightTrigger" ($rocket[0]+".rightTrigger"); //Make the rocket into an active rigidBody string $rigidBody = `rigidBody -active -m 1 -dp 0 -sf 0.2 -df 0.2 -b 0.6 -l 0 -tf 200 -iv 0 0 0 -iav 0 0 0 -c 0 -pc 0 -i 0 0 0 -imp 0 0 0 -si 0 0 0 -sio none $rocket[0]`; //Make the selection into a active rigid body setAttr ($rigidBody+".damping") 1; //Assign gravity to the rocket. string $carGravity[] = `gravity -pos 0 0 0 -m 9.8 -att 0 -dx 0 -dy -1 -dz 0 -mxd -1 -vsh none -vex 0 -vof 0 0 0 -vsw 360 -tsr 0.5`; connectDynamic -f $carGravity[0] $rocket[0]; //Create all the locators that are needed to calculate the facing vector string $objCenterLoc[] = `spaceLocator -p 0 0 0`; //This locator represents the center of the "vehicle" pointConstraint -offset 0 0 0 -weight 1 $rocket[0] $objCenterLoc[0]; //Constrain the locator to the center of the "vehicle" $objCenterLoc[0] = `rename $objCenterLoc[0] "rocket_center"`; string $objFrontLoc[] = `spaceLocator -p 0 0 0`; $objFrontLoc[0] = `rename $objFrontLoc[0] "rocket_FrontChild"`; move -a 0 1 0 $objFrontLoc[0]; string $vectorCalcLoc[] = `spaceLocator -p 0 0 0`; $vectorCalcLoc[0] = `rename $vectorCalcLoc[0] "rocket_Front"`; pointConstraint -offset 0 0 0 -weight 1 $objFrontLoc[0] $vectorCalcLoc[0]; parent $objFrontLoc[0] $rocket[0]; // Create the vector calculation network string $vectorCalc = `shadingNode -asUtility plusMinusAverage`; //This node will calculate the vector of the "vehicle" setAttr ($vectorCalc+".operation") 2; //Set node to subtract connectAttr -f ($objCenterLoc[0]+".translate") ($vectorCalc+".input3D[1]"); //Connect the first locator the the vector calc node connectAttr -f ($vectorCalcLoc[0]+".translate") ($vectorCalc+".input3D[0]"); //Connect the second locator the the vector calc node string $speedMult = `shadingNode -asUtility multiplyDivide`; //This node will act as a way to control the speed of the "vehicle" connectAttr -force ($vectorCalc+".output3D") ($speedMult+".input1"); //Connect the vector and speed nodes setAttr ($speedMult+".input2X") 0; setAttr ($speedMult+".input2Y") 0; setAttr ($speedMult+".input2Z") 0; connectAttr -force ($speedMult+".output") ($rigidBody+".impulse"); connectAttr -f ($rocket[0]+".thrustOutput") ($speedMult+".input2X"); connectAttr -f ($rocket[0]+".thrustOutput") ($speedMult+".input2Y"); connectAttr -f ($rocket[0]+".thrustOutput") ($speedMult+".input2Z"); //This expression controls the velocity. It allows the max speed to be tweaked by the totalThrust attribute string $cmd = (""+$rocket[0]+".thrustOutput = ("+$rocket[0]+".rightTrigger * "+$rocket[0]+".totalThrust);"); expression -s $cmd -o $rocket[0] -ae 1 -uc all -n "rocket_VelocityControl"; playbackOptions -loop once -min 1 -max 5000; //Sets the time range // At this point the rocket has been created and now we can have a little fun... Lets hook up a particle system so that when you hit the thrust particles shoot out. string $emitter[] = `emitter -pos 0 0 0 -type direction -r 100 -sro 0 -nuv 0 -cye none -cyi 1 -spd 1 -srn 0 -nsp 1 -tsp 0 -mxd 0 -mnd 0 -dx 0 -dy -1 -dz 0 -sp 0.1`; string $particle[] = `particle`; connectDynamic -em $emitter[0] $particle[0]; string $cmd = (""+$emitter[0]+".rate = "+$rocket[0]+".thrustOutput * 500"); expression -s $cmd -o $rocket[0] -ae 1 -uc all -n "rocket_ParticleControl"; setAttr ($emitter[0]+".translateY") -2; parent $emitter[0] $rocket[0]; setAttr ($emitter[0]+".speed") 15; //Setup particle look and feel setAttr ($particle[0]+".lifespanMode") 2; setAttr ($particle[0]+".lifespanRandom") 0.5; setAttr ($particle[0]+".conserve") .9; setAttr ($particle[1]+".particleRenderType") 6; addAttr -is true -ln "colorAccum" -at bool -dv false $particle[1]; addAttr -is true -ln "useLighting" -at bool -dv false $particle[1]; addAttr -is true -ln "lineWidth" -at long -min 1 -max 20 -dv 1 $particle[1]; addAttr -is true -ln "tailFade" -at "float" -min -1 -max 1 -dv 0 $particle[1]; addAttr -is true -ln "tailSize" -at "float" -min -100 -max 100 -dv 1 $particle[1]; addAttr -is true -ln "normalDir" -at long -min 1 -max 3 -dv 2 $particle[1]; setAttr ($particle[1]+".lineWidth") 2; setAttr ($particle[1]+".tailFade") 1; setAttr ($particle[1]+".tailSize") 3; setAttr ($particle[1]+".colorAccum") 1; addAttr -ln "rgbPP" -dt vectorArray $particle[1]; addAttr -ln "rgbPP0" -dt vectorArray $particle[1]; arrayMapper -target $particle[1] -destAttr rgbPP -inputV ageNormalized -type ramp; rename $rocket[0] "Rocket"; } global proc setupXboxControlServer() { //Check to see if the server is already running. If it is then break and warn. Otherwise start the server. string $joyServer = "xenon"; string $allDevices[] = `listInputDevices`; int $test = 0; for ($i = 0; `size($allDevices)` > $i; ++$i) { if($allDevices[$i] == $joyServer) { $test = 1; warning "Server Already Running."; break; } } if($test == 0) { //Start the joystick server defineDataServer -device $joyServer -server XenonController; //Start the maya data server. This will allow us to connect the gamepad } }