Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Scripting a vehicle

Kume Grant
Registered User
Join date: 30 Aug 2005
Posts: 7
12-03-2006 05:53
Hi. I'm wondering if it's possable to script a vehicle to slowly decend while onlt bing able to move left and right back and forth. without banking and pressing the left and right arrow keys to go left or right.
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
12-03-2006 09:26
From: Kume Grant
Hi. I'm wondering if it's possable to script a vehicle to slowly decend while onlt bing able to move left and right back and forth. without banking and pressing the left and right arrow keys to go left or right.


short answer is yes :)
Sounds like a balloon script?
check teh forums for a post or the wiki vehicle tutorial
grumble Loudon
A Little bit a lion
Join date: 30 Nov 2005
Posts: 612
12-03-2006 23:00
You could make a vechical using a timer and manualy controling it.

This is how my AutoBahn vechical works.
Here is a hacked version that fun to crash into trees with.
CODE

//Fun car script, Can even drive upside down
//From Simple car script V1.0
//Released into the public domain by grumble Loudon and LaserFur Leonov

integer m_DesiredSpeed = 0; // forward/ reverse
integer m_WheelPos = 0; // Right / left

//
//*********************************************************************************
vector m_VelLast;
rotation m_RotLast;

UpdateStatus(){
string msg;

msg = "Wheel = " + (string) m_WheelPos;
msg += "\nSpeed = " + (string) m_DesiredSpeed;
msg += "\nEnergy = " + (string) llGetEnergy();
llMessageLinked(LINK_ALL_CHILDREN, 1, msg, NULL_KEY);
}

//*********************************************************************************
default
{
state_entry()
{
llMessageLinked(LINK_ALL_CHILDREN, 0, "stop", NULL_KEY);
llCollisionSound("", 0.0);
llSetSitText("Drive");
llStopSound();

llSetTimerEvent(0.0);

llSitTarget(<0.1, 0.35, 0.6>, <0,-0.2,0,1>);
llSetCameraEyeOffset(<-5.0, 0.0, 2.5>);
llSetCameraAtOffset(<0.0, 0.0, 1.0>);

// remove all flags
llRemoveVehicleFlags(-1);

llSetStatus(STATUS_PHYSICS, FALSE);
llSetBuoyancy(1); //floats

llSetForceAndTorque(<0,0,0>,<0,0,0>,TRUE);


}
//****************************************************************************
on_rez(integer startPram){
llResetScript();
}
//****************************************************************************

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
{
// You sit and are owner so get controls
llSetStatus(STATUS_PHYSICS, TRUE);
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, TRUE);
llSetForceAndTorque(<0,0,0>,<0,0,0>,TRUE);
llRequestPermissions(agent,PERMISSION_TAKE_CONTROLS);

//timer is turned on after premissions are ok
}
}
else
{
// You stand so car stops
// llMessageLinked(LINK_ALL_CHILDREN, 0, "stop", NULL_KEY);
llSetForceAndTorque(<0,0,0>,<0,0,0>,TRUE);
llSetStatus(STATUS_PHYSICS, FALSE);
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
llReleaseControls();
llStopSound();
llSetTimerEvent(0.0);
}
}

}
//****************************************************************************
run_time_permissions(integer perm)
{
if (perm)
{
// Take these controls and lets go
llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT | CONTROL_UP | CONTROL_DOWN, TRUE, FALSE);

m_DesiredSpeed=0;
m_WheelPos = 0; // Right / left
UpdateStatus();
llLoopSound("car idle",0.3);
llSetTimerEvent(0.3);
}
}
//****************************************************************************
control(key id, integer level, integer edge)
{

if(level & CONTROL_FWD)
{
// Set cruising speed faster
if(m_DesiredSpeed < 20) //limit forward speed
{
m_DesiredSpeed +=1;
UpdateStatus();
}
}
if(level & CONTROL_BACK)
{
// Set cruising speed slower
if(m_DesiredSpeed > 10) //limit reverse speed
{
m_DesiredSpeed -=1;
UpdateStatus();
}
}
if((level & CONTROL_FWD) && (level & CONTROL_BACK))
{
// Forwards and Backwards <-- Brakes or stops
// llMessageLinked(LINK_ALL_CHILDREN, 0, "brake", NULL_KEY);
m_DesiredSpeed=0;
UpdateStatus();
}
if(level & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
{
m_WheelPos += 1; // Turn right
UpdateStatus();
}
if(level & (CONTROL_LEFT|CONTROL_ROT_LEFT))
{
m_WheelPos -= 1 ; // Turn left
UpdateStatus();
}
if(level & CONTROL_UP)
{
// add features for when you press up
}
if(level & CONTROL_DOWN)
{
// Added feature for when you press down
}

}
//****************************************************************************
timer()
{

// the timer actually moves vehicle
vector Force;
vector torque;

vector curVel = llGetVel();
rotation rot = llGetRot();
curVel /= rot; // Un-rotate curVel to our orentation

Force.x = m_DesiredSpeed; //forward
Force.y = 0; //Right left
Force.z = 0; //up down

Force -= curVel; // remove current speed
Force *= .3; //dampen accel/decell

Force.z += -0.58; //make gravity again, but in local direction.

Force *= llGetMass();

torque.x = 0;
torque.y = 0;
torque.z = 0;

llApplyImpulse(Force,TRUE);

torque.x = 0;
torque.y = 0;
torque.z = m_WheelPos * -0.5;
llApplyRotationalImpulse(torque, TRUE);
if (m_WheelPos != 0){
m_WheelPos =0;
UpdateStatus();
};

} //timer
}