// Camera control rocket script // Rezzes a rocket, fires it off, has the firer's camera follow the // rocket. No remote control of rocket as yet but that would be // possible. // The rocket will have some sort of simple propulsion script and // maybe die when it gets out of range or out of the sim (since the // controller won't be able to find it on the sensor... or maybe it // won't care). // Ordinal Malaprop // 2006-06-16 integer gPerms = 0; string gAnim = "hold_R_bazooka"; default { state_entry() { gPerms = PERMISSION_CONTROL_CAMERA | PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION; } attach(key id) { // We need permissions for this if (id == llGetOwner()) { llRequestPermissions(id, gPerms); } else if ((llGetPermissions() & gPerms) == gPerms) { // stop everything if detached, just to be tidy llStopAnimation(gAnim); llReleaseCamera(llGetOwner()); llReleaseControls(); } } run_time_permissions(integer perms) { if ((llGetPermissions() & gPerms) == gPerms) { // take control of mouselook fire button llTakeControls(CONTROL_ML_LBUTTON, TRUE, FALSE); llStartAnimation(gAnim); llOwnerSay("Enter mouselook and click left mouse button to " + "fire rocket"); } } control(key id, integer held, integer change) { // Fire rocket when in mouselook and press button. // You could, theoretically, fire more than one rocket. // The camera will follow the last one fired. if ((held & change & CONTROL_ML_LBUTTON)) { rotation rot = llGetRot(); vector fwd = llRot2Fwd(llGetRot()); llRezObject("rocket", llGetPos() + fwd, fwd * 20, rot, 1); } } object_rez(key id) { // Rezzed a rocket? start following it with a sensor llSensorRepeat("", id, ACTIVE, 96.0, PI, 0.1); } no_sensor() { // Can't find the rocket? Stop trying and reset the camera. llSensorRemove(); llClearCameraParams(); } sensor(integer n) { // Found the rocket? Move the camera. // Focus on the rocket... vector focus = llDetectedPos(0); // and have camera 3m behind rocket in its direction of movement. vector camera = focus - llVecNorm(llDetectedVel(0)) * 3; llSetCameraParams([ CAMERA_ACTIVE, TRUE, CAMERA_FOCUS, focus, CAMERA_POSITION, camera ]); } }