Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

newbie needs some help

Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
10-29-2005 08:14
I'm just getting into scripting, and as I have little to no relevant programming experience, the scripting language has thrown me for a loop. mostly I'm having trouble getting my head around changing states, calling scripts to run in other objects, and the coordinate system in the game. I come from 8+ years of designing maps for Quake2-3, Half-life 1&2, and the unreal series so I have experience in "scripting" from a visual programming standpoint (since that's what they use in the map editors), but not from an actual coding perspective.

My 1st problem is a vehicle script that I cut N pasted, and tweaked some variables to get it to run right. it's working great except for two issues. the first is the camera. for some reason, no matter how I change the llSetCameraEyeOffset and llSetCameraAtOffset. the camera view stays the same: namely it's 90 degrees to the "right" of the front of the bike (assuming you're sitting on the bike), and at the ground level. I built my bike wrong to start off with, as it was orientated on the Y axis instead of the X axis, and it caused some problems until I was able to find a prim on the bike that was orientated the correct way and used that as my base prim. From what I understand the "eye" command tells where the camera is relative to the center of the object and the "at" command tells where it's looking to. if this is right, the camera should be behind the bike and a little up looking down slightly to just in front of the bike. But as I stated, this is not the case

The other problem I'm having is that once in a while (about 1 out of 10 times) when the avatar sits on the bike, it will sit on it upside down, doesn't run the sitting animation, and the bike won't run. any help solving these two problems would be very helpful.

CODE
key agent;
vector PUSH_OFF = <0, 10, 10>;
integer gLightsOn = FALSE;
integer iChan = 0;
key owner;

vector startColor = <1,0.5,0.5>;
vector endColor = <1,0,0>;
integer onoff = TRUE;

string last_wheel_direction;
string cur_wheel_direction;


default
{
state_entry()
{
gLightsOn = FALSE;
llMessageLinked(LINK_SET, gLightsOn, "lights_off", "");
llSetSitText("Ride");
llSitTarget(<.24, 0.05, 0.3>, <0.0, .075, 0.0, 1>);
llSetCameraEyeOffset(<0, -4, 4>);
llSetCameraAtOffset(<0, 2, 2>);
llSetVehicleFlags(-1);
llSetVehicleType(VEHICLE_TYPE_CAR);
llSetVehicleFlags(VEHICLE_FLAG_NO_DEFLECTION_UP |
VEHICLE_FLAG_LIMIT_ROLL_ONLY | VEHICLE_FLAG_LIMIT_MOTOR_UP);
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.2);
llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.80);
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 0.10);
llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 0.10);

llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 1.0);
llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_ TIMESCALE, 0.2);
llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.1);
llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY _TIMESCALE, 0.5);


llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <1000.0, 0.50, 1000.0>);
llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <10.0, 5.0, 1000.0>);


llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION _EFFICIENCY, 0.75);
llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION _TIMESCALE, 0.25);

llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, 1.0);
llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 0.01);

owner = llGetOwner();
llListen(iChan,"",owner,"");
}

//touch_start(integer num)
//{
//if(llDetectedKey(0) != llGetOwner())
//{
//llWhisper(0, "AKIRA bike");

//}
//else
//{
//if(llAvatarOnSitTarget() != llGetOwner()) llWhisper(0, "Right Click and choose 'Ride' from the pie menu.");
//}
//}

listen(integer chan, string name, key id, string msg)
{
list command = llCSV2List(msg);
// Lights
if (chan == iChan & msg == "lights on")
{
gLightsOn = TRUE;
llMessageLinked(LINK_SET, gLightsOn, "lights_on", "");
}
if (chan == iChan & msg == "lights off")
{
gLightsOn = FALSE;
llMessageLinked(LINK_SET, gLightsOn, "lights_off", "");
}
// Colour presets
if(llList2String(command, 0) == "color" | llList2String(command, 0) == "colour")
{
if(llList2String(command, 1) == "red")
{
startColor = <1,0.5,0.5>;
endColor = <1,0,0>;
}
if(llList2String(command, 1) == "green")
{
startColor = <0.5,1,0.5>;
endColor = <0,1,0>;
}
if(llList2String(command, 1) == "blue")
{
startColor = <0,1,1>;
endColor = <0,0.25,1>;
}
if(llList2String(command, 1) == "purple")
{
startColor = <1,0.5,1>;
endColor = <1,0,1>;
}
if(llList2String(command, 1) == "yellow")
{
startColor = <1,1,0.5>;
endColor = <1,1,0>;
}
}
// Colour via RGB values
if(llList2String(command, 0) == "rgb")
{
if(llList2String(command, 1) != "")
{
startColor = <1,0.5,0.5>;
endColor = <1,0,0>;
}
}
}



changed(integer change)
{
if (change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if (agent)
{
if (agent != llGetOwner())
{
llSay(0, "You aren't the owner");
llUnSit(agent);
llPushObject(agent, <0,0,100>, ZERO_VECTOR, FALSE);
}
else
{
llTriggerSound("bike_start",1);
llSleep(.4);
llSetStatus(STATUS_PHYSICS | STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, TRUE);
llSleep(.1);
llCollisionSound("", 0);
llSetTimerEvent(0.5);
llLoopSound("bike_idle",1);
llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
}
}
else
{
llSetTimerEvent(0);
llStopSound();
llSetStatus(STATUS_PHYSICS | STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
llReleaseControls();
llStopAnimation("motorcycle_sit");
llPushObject(llGetOwner(), PUSH_OFF, <0,0,0>, TRUE);
gLightsOn = FALSE;
llMessageLinked(LINK_SET, gLightsOn, "lights_off", "");
}
}

}

run_time_permissions(integer perm)
{
if (perm)
{
llStartAnimation("motorcycle_sit");
llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT | CONTROL_UP | CONTROL_DOWN, TRUE, FALSE);
}
}
control(key id, integer level, integer edge)
{
vector angular_motor;
vector vel = llGetVel();

if(level & CONTROL_FWD)
{
llLoopSound("bike_drive",1);
llMessageLinked(LINK_SET, gLightsOn, "brake_off", "");
if(!llGetStatus(STATUS_PHYSICS))
{
llSetStatus(STATUS_PHYSICS | STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, TRUE);
llCollisionSound("", 0);
}

llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIREC TION, <29.1,0,0>);
}
if(level & CONTROL_BACK)
{
llLoopSound("bike_drive",1);
llMessageLinked(LINK_SET, gLightsOn, "brake_on", "");
//llSetVehicleRotationParam(VEHICLE_REFERENCE_FRAME, <0, 0, 1, 0> );
if(!llGetStatus(STATUS_PHYSICS))
{
llSetStatus(STATUS_PHYSICS | STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, TRUE);
llCollisionSound("", 0);
}
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIREC TION, <-10,0,0>);
}

if(level & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
{
llLoopSound("bike_drive",1);
//llSetVehicleRotationParam(VEHICLE_REFERENCE_FRAME, <0, 0, 0, 1> );
angular_motor.x += 25;
angular_motor.z -= 10;
}
if(level & (CONTROL_LEFT|CONTROL_ROT_LEFT))
{
llLoopSound("bike_drive",1);
//llSetVehicleRotationParam(VEHICLE_REFERENCE_FRAME, <0, 0, 0, 1> );
angular_motor.x -= 25;
angular_motor.z += 10;
//llWhisper(0,(string)llGround(<0,0,0>) + " -- " + (string)llGetPos());
}
if(level & (CONTROL_UP))
{
//llSetVehicleRotationParam(VEHICLE_REFERENCE_FRAME, <0, 0, 0, 1> );
angular_motor.y -= 75;
}
if(level & (CONTROL_DOWN))
{
//llSetVehicleRotationParam(VEHICLE_REFERENCE_FRAME, <0, 0, 0, 1> );
angular_motor.y += 75;
}
if((edge & CONTROL_FWD) && (level & CONTROL_FWD))
{
// We have a few message links to communicate to the other
// scritps when we start to accelerate and let off the gas.
llMessageLinked(LINK_SET, 0, "burst", "");
}
if((edge & CONTROL_BACK) && !(level & CONTROL_BACK))
{
llMessageLinked(LINK_SET, gLightsOn, "brake_off", "");
}

llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor);

}
timer()
{
llLoopSound("bike_idle",1);
}

}
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
10-29-2005 11:10
I found out that the problem is the "motorcycle_sit" animation. for some reason when I use this default animation for sitting on the bike, it hard locks the camera at 90 degrees out, no matter how I modify a vehicle (even a cube with the script), the view is locked here with that animation. so my question is, can I fix this animation problem in SL or do I need to get a 3rd party program ?
Kenn Nilsson
AeonVox
Join date: 24 May 2005
Posts: 897
10-29-2005 21:41
CODE

llSetCameraEyeOffset(<0, -4, 4>);
llSetCameraAtOffset(<0, 2, 2>);


Take a look at those two functions in the WIKI

That's what's causing your problem.
_____________________
--AeonVox--

Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms chasing ghosts, eating magic pills, and listening to repetitive, addictive, electronic music.
Polaris Padar
Registered User
Join date: 2 Sep 2005
Posts: 24
11-09-2005 11:11
Yeh you cant sit before setting the camera offsets :)
camera offsets dont work after sitting