Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Any vehicle scripts with avatar style movement?

Harris Hare
Second Life Resident
Join date: 5 Nov 2004
Posts: 301
04-14-2005 10:26
This may seem like an akward question, but has anyone ever seen a vehicle script or actual vehicle that behaves the same way an avatar behaves? By this I mean, when you drive the vehicle, the movement properties it displays are almost identical to the natural way an avatar moves?

For example: When you turn left or right, you simply rotate staying even with the world's z-axis... when you press forward you move forward at a consistant rate until you release the key and come to a (near) immediate stop... when you press "page-up" you move up at a consistant rate until you release the key and come to a stop and hover at that posision... etc.
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
04-14-2005 11:35
I've written a few things similar to this. I think the key is to use something like llMoveToTarget and define all of these properties manually.

This has been tested:
CODE
float speed = 10;
float backPercent = 0.5;
float turnSpeed = 20;
float maxSpeed = 10;
float dampingPercent = 0.75;
rotation mod;
rotation negMod;
vector current;
default
{
state_entry()
{
llCollisionSound("",0);
mod = llEuler2Rot(<0,0,turnSpeed * PI / 180.0>);
negMod = llEuler2Rot(<0,0,-1 * turnSpeed * PI / 180.0>);
llSitTarget(<1,0,0.5>,<0,0,0,1>);
}

changed(integer change)
{
if(change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if(agent == llGetOwner()) llRequestPermissions(agent,PERMISSION_TAKE_CONTROLS);
else
{
llSetStatus(STATUS_PHYSICS,FALSE);
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, TRUE);
llStopMoveToTarget();
llReleaseControls();
}
}
}
run_time_permissions(integer perm)
{
if(perm)
{
llMoveToTarget(llGetPos(),0.3);
llSetStatus(STATUS_PHYSICS,TRUE);
vector rotIt = llRot2Euler(llGetRot());
llRotLookAt(llEuler2Rot(<0,0,rotIt.z>),0.3,0.3);
llSetRot(llEuler2Rot(<0,0,rotIt.z>));
llSleep(1);
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE);
llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_LEFT | CONTROL_ROT_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT | CONTROL_RIGHT | CONTROL_UP | CONTROL_DOWN, TRUE, FALSE);
}
}
control(key id, integer level, integer edge)
{
rotation rot = llGetRot();
if(level & CONTROL_FWD)
{
llSetTimerEvent(0.5);
current += speed * llRot2Fwd(llGetRot());
if(llVecMag(current) > maxSpeed) current = maxSpeed * current / llVecMag(current);
}
if(level & CONTROL_BACK)
{
llSetTimerEvent(0.5);
current -= backPercent * speed * llRot2Fwd(llGetRot());
if(llVecMag(current) > maxSpeed) current = maxSpeed * current / llVecMag(current);
}
if(level & (CONTROL_LEFT | CONTROL_ROT_LEFT))
{
rot = mod * rot;
}
if(level & (CONTROL_RIGHT | CONTROL_ROT_RIGHT))
{
rot = negMod * rot;
}
if(level & CONTROL_UP)
{
llSetTimerEvent(0.5);
current += speed * llRot2Up(llGetRot());
if(llVecMag(current) > maxSpeed) current = maxSpeed * current / llVecMag(current);
}
if(level & CONTROL_DOWN)
{
llSetTimerEvent(0.5);
current -= speed * llRot2Up(llGetRot());
if(llVecMag(current) > maxSpeed) current = maxSpeed * current / llVecMag(current);
}
llRotLookAt(rot,0.3,0.3);
llMoveToTarget(llGetPos() + current,0.3);
}

timer()
{
llSetTimerEvent(0.2);
current *= dampingPercent;
if(llVecMag(current) < 0.5)
{
llSetTimerEvent(0);
current = <0,0,0>;
}
}
}
_____________________
---