Chapter 4 lecture… Read on!
Step 1:
// UW Week 4.1 - canon 1
float SPEED = 18.0; // m/sec
fire() {
vector dir = <0,0,1.0>; // Up
vector vel = dir * SPEED; // fire it SPEED in the right direction
vector pos = llGetPos() + <0,0,0.6>; // shell will appear a little beyond the end
integer delay = 5 + (integer)llFrand(5.0); // how many tenths of seconds it should fly upward
// get the name of the first object in inventory
string bullet = llGetInventoryName(INVENTORY_OBJECT, 0);
llRezObject(bullet, pos, vel, ZERO_ROTATION, delay);
}
default
{
touch(integer p) {
fire();
}
}
Step 2: Get the demo shell from me if you aren’t ready to do your own!
If you do this yourself, you’ll need to set your shell to physical before you take it into canon inventory.
// Simple firework shell
// Vex Streeter for Scripting Your World
explode() {
vector color = ; // pick a random color
llParticleSystem([
PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE,
// particles live for 10 seconds, but the shell only bursts for 1 second
PSYS_SRC_MAX_AGE, 1.0,
PSYS_PART_MAX_AGE, 10.0,
// every 5 seconds
PSYS_SRC_BURST_RATE, 5.0,
// 500 particles
PSYS_SRC_BURST_PART_COUNT, 500,
// burst from near the shell
PSYS_SRC_BURST_RADIUS, 0.1,
// particles burst out at 2m/sec
PSYS_SRC_BURST_SPEED_MIN, 2.0,
PSYS_SRC_BURST_SPEED_MAX, 2.0,
PSYS_SRC_ACCEL, <0.0,0.0,-0.8>,
// constant color for the particles
PSYS_PART_START_COLOR, color,
PSYS_PART_END_COLOR, color,
// start nearly opaque then become transparent
PSYS_PART_START_ALPHA, 0.9,
PSYS_PART_END_ALPHA, 0.0,
// start
PSYS_PART_START_SCALE, <0.25,0.25,0>,
PSYS_PART_END_SCALE, <0.01,0.01,0>,
// particles glow, change size, and blow in the wind
PSYS_PART_FLAGS, PSYS_PART_EMISSIVE_MASK |
PSYS_PART_INTERP_SCALE_MASK |
PSYS_PART_WIND_MASK
]);
llSleep(.5); // wait for 2sec
llParticleSystem([]); // then stop the system
}
default
{
on_rez(integer param) {
if (param!=0) {
// kill the shell if it hits the edge of the sim
llSetStatus(STATUS_DIE_AT_EDGE, TRUE);
// make it temporary
llSetPrimitiveParams([PRIM_TEMP_ON_REZ, TRUE]);
// after this many tenths of seconds, we'll explode
llSetTimerEvent(param * 0.1);
}
}
state_entry() {
}
touch_end(integer p) {
explode();
}
// explode when the timer goes off
timer() {
explode();
llDie();
}
}
Second version!
// UW Week 4.3 - canon 2
float SPEED = 18.0; // m/sec
fire() {
rotation rot = llGetRot();
vector dir = <0,0,1.0> * rot; // same direction we're pointed
vector vel = dir * SPEED; // fire it SPEED in the right direction
vector scale = llGetScale(); // how big is the canon?
float startz = ( scale.z / 2.0 ) + 0.1; // half the hight plus a little
vector pos = llGetPos() + <0,0,startz> * rot; // shell will appear a little beyond the end
integer delay = 5 + (integer)llFrand(5.0); // how many tenths of seconds it should fly upward
// get the name of the first object in inventory
string bullet = llGetInventoryName(INVENTORY_OBJECT, 0);
llRezObject(bullet, pos, vel, ZERO_ROTATION, delay);
}
default
{
touch(integer p) {
fire();
}
}
