Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Looking for code to change view while sitting.

Mortus Allen
Registered User
Join date: 28 Apr 2007
Posts: 528
10-16-2008 15:17
Alright what I am really looking to do is to script the Captains Chair of a yacht I am building so that the pilots/drivers view is froward while moving throttled forward, backward while moving backward, and ideally deflect in the direction the vessel is turning. For this I need a way to change the view angle without having to get up.
Bounder Jimenez
programmer/designer
Join date: 12 Oct 2005
Posts: 45
10-16-2008 19:30
heres some code you can play with...

CODE

key driver = NULL_KEY;

vector normalfocusoffset = <2.0,0.0,1.0>;
vector lastoffset = ZERO_VECTOR;

setCamera(integer active,vector focusoffset)
{
if(lastoffset != focusoffset)
{
lastoffset = focusoffset;
float dist = 1.0;

llSetCameraParams([
CAMERA_ACTIVE, active,
CAMERA_BEHINDNESS_ANGLE, 0.0, //(0 to 180) degrees
CAMERA_BEHINDNESS_LAG, 0.0, //(0 to 3) seconds
CAMERA_DISTANCE, dist, //(0.5 to 10) meters
// CAMERA_FOCUS, focus, //Region-relative position
CAMERA_FOCUS_LAG, 0.1 , //(0 to 3) seconds
CAMERA_FOCUS_LOCKED, FALSE, //(TRUE or FALSE)
CAMERA_FOCUS_THRESHOLD, 0.0, //(0 to 4) meters
CAMERA_PITCH, 0.0, // (-45 to 80) degrees
// CAMERA_POSITION, pos, //Region-relative position
CAMERA_POSITION_LAG, 0.5, //(0 to 3) seconds
CAMERA_POSITION_LOCKED, TRUE, //(TRUE or FALSE)
CAMERA_POSITION_THRESHOLD, 0.5, //(0 to 4) meters
CAMERA_FOCUS_OFFSET, focusoffset //<-10,-10,-10> to <10,10,10> meters
]);
}
}

default
{
state_entry()
{
key driver = llAvatarOnSitTarget();
if(driver != NULL_KEY)
llRequestPermissions(driver,PERMISSION_TAKE_CONTROLS |
PERMISSION_CONTROL_CAMERA);
}

changed(integer change)
{
key agent = llAvatarOnSitTarget();
if(agent != NULL_KEY)
{
driver = agent;
llRequestPermissions(driver,PERMISSION_TAKE_CONTROLS |
PERMISSION_CONTROL_CAMERA);
} else if(driver != NULL_KEY)
{
llReleaseControls();
llReleaseCamera(driver);
driver = NULL_KEY;
}
}
run_time_permissions(integer perm)
{
if (perm & PERMISSION_TAKE_CONTROLS)
{
llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT |
CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT |
CONTROL_UP | CONTROL_DOWN, TRUE, FALSE);
}
if (perm & PERMISSION_CONTROL_CAMERA)
{
setCamera(TRUE,normalfocusoffset);
}
}

control(key id, integer level, integer edge)
{
vector focusoffset = normalfocusoffset;

if(level & (CONTROL_LEFT | CONTROL_ROT_LEFT))
focusoffset.y += 2.0;
if(level & (CONTROL_RIGHT | CONTROL_ROT_RIGHT))
focusoffset.y += -2.0;
if(level & CONTROL_BACK)
focusoffset.x += -7.0;
if(level & CONTROL_UP)
focusoffset.z += 2.0;
if(level & CONTROL_DOWN)
focusoffset.z -= 3.0;
setCamera(TRUE,focusoffset);
}
}
Mortus Allen
Registered User
Join date: 28 Apr 2007
Posts: 528
10-23-2008 14:38
Hey Bounder, thanks.