CannonBall

This script should be placed inside of your cannonball prim. The cannonball should be a physical prim and placed inside of the cannon and named "CannonBall". If you let the cannonball with the script fall and hit the ground, it very well may activate the collision detection and enter data into the prim's description field. It shouldn't matter, but to keep things clean, while in edit mode, I usually clean out the field, reset the script (Tools -> Reset Scripts in Selection) and then without leaving Edit mode, I take it or a copy into my inventory. Inside your cannonball, you'll also need the tracer prim which in turn contains a script of its own.

Return to main Cannon page

code format="lsl2" //Written by Jeff Mao //Distributed under a Creative Commons Attribution 3.0 license [CC-BY](http://creativecommons.org/licenses/by/3.0/) //If you have questions about this, please feel free to contact me at jmao@mac.com. //Please share alterations, improvements, lesson plans related to this simulation, etc. //v1.98 integer myVar = 1; //start-stop counter so that collision alert only occurs once

//details for tracer rounds string object = "tracer"; // Name of object in inventory vector relativePosOffset = <0.0, 0.0, 0.0>; vector relativeVel = <0.0, 0.0, 0.0>; rotation relativeRot = <0.0, 0.0, 0.0, 0.0>; integer startParam = 10;

//details for counter for tracer rounds float gap = .05; //tracer round every ___ seconds. Note this doesn't hold up as scripts just don't tell time well. integer tracercount = 0;

default {   on_rez(integer start_param) {       float time = llGetTimeOfDay; vector startPos = llGetPos; string mydata = "x"+(string)startPos.x +"y"+(string)startPos.y +"z"+(string)startPos.z +"t"+ (string)time; llSetObjectName(mydata); llSetTimerEvent(gap); }

collision(integer num_detected) {       if (myVar == 1) {       float time = llGetTimeOfDay; vector endPos = llGetPos; string mydata = "x"+(string)endPos.x +"y"+(string)endPos.y +"z"+(string)endPos.z +"t"+ (string)time+":"; llSetObjectDesc(mydata); myVar = 2; state done; }   }

land_collision(vector pos) {       if (myVar == 1) {           float time = llGetTimeOfDay; string mydata = "x"+(string)pos.x +"y"+(string)pos.y +"z"+(string)pos.z +"t"+ (string)time+":"; llSetObjectDesc(mydata); myVar = 2; state done; }   }

timer {       ++tracercount; vector myPos = llGetPos; rotation myRot = llGetRot;

vector rezPos = myPos+relativePosOffset*myRot; vector rezVel = relativeVel*myRot; rotation rezRot = relativeRot*myRot;

llRezAtRoot(object, rezPos, rezVel, rezRot, startParam);

if (tracercount == 15) {          llSetTimerEvent(0); }   }    touch_start(integer num_detected) {       llSay(0,llGetObjectDesc); llSetTimerEvent(0); state done; } }

state done {   state_entry {       llSetTimerEvent(0); }   touch_start(integer num_detected) {               llSetStatus( STATUS_PHYSICS, FALSE ); llSay(0,"\n"+llGetObjectDesc); }

}

code