Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

camera "follow" a object

Mrc Homewood
Mentor of Randomness
Join date: 24 Feb 2007
Posts: 779
11-09-2008 04:54
ive been trying to figure this out i know that you can only use camera permissions only if you are wearing something or sitting on something but is there a way to wear a hud and have your cam follow the object around?

and if so how would someone be able to script that step by step? im completly last thing weekend.
Void Singer
Int vSelf = Sing(void);
Join date: 24 Sep 2005
Posts: 6,973
11-09-2008 06:11
far as I know they don't have to worn or attached, the difference is that you get a permission request dialog if they aren't attached/sat upon.... examples would be cam folowers
_____________________
|
| . "Cat-Like Typing Detected"
| . This post may contain errors in logic, spelling, and
| . grammar known to the SL populace to cause confusion
|
| - Please Use PHP tags when posting scripts/code, Thanks.
| - Can't See PHP or URL Tags Correctly? Check Out This Link...
| -
Twisted Laws
Registered User
Join date: 19 Jun 2006
Posts: 9
11-10-2008 07:23
this must go in a hud or attachment option.....

CODE


// twisted laws
// camera control script .. this must go in an attachment or hud

// you can change the camera offsets right here
vector posoffset = <-1.0,0.0,0.0>;
vector focusoffset = <1.0,0.0,0.0>;
// if auto_set_camera is TRUE then we ignore the posoffset and
// focusoffset and try and compute a view that the object would
// see looking out of its x axis
integer auto_set_camera = FALSE;
integer controlling = FALSE;
key watchkey = NULL_KEY;

// call this to start the camera watching a specific key (can be
// object or avatar). note that this requests permissions so
// a piece of this is down in run_time_permissions. this is setup
// to request camera permissions only when necessary and release
// them when we don't need it
start(key obj)
{
watchkey = obj;
if(auto_set_camera)
{
list sizes = llGetBoundingBox(obj);
vector scale = llList2Vector(sizes,1)-llList2Vector(sizes,0);
if(scale.x > 1.0)
posoffset.x = -1.5;
else
posoffset.x = -0.75;
posoffset.z = scale.z + 0.25;
focusoffset.z = posoffset.z - 0.20;
}
llRequestPermissions(llGetOwner(),PERMISSION_CONTROL_CAMERA);
}

// called to stop the camera
stop()
{
llSetTimerEvent(0.0);
setCamera(FALSE);
controlling = FALSE;
llReleaseCamera(llGetOwner());
watchkey = NULL_KEY;
}

// call this repeatedly to update camera position with active = TRUE
// note camera is set as locked at a specific position
// focused on a specific position as frequently as called
// by the timer. so this is a bit jerky and i don't know
// a good way to fix that
setCamera(integer active)
{
vector pos = llGetPos();
rotation rot = llGetRootRotation();
vector focus;
// if active and we have something to watch
if(active && watchkey != NULL_KEY)
{
// get watchkey's current position and rotation
list details = llGetObjectDetails(watchkey,[OBJECT_POS,OBJECT_ROT]);
if(details == [])
{
stop();
return;
}
else
{
if(auto_set_camera)
rot = llList2Rot(details,1);
pos = llList2Vector(details,0);
}
}
// compute camera position and focus position
focus = pos + focusoffset * rot;
pos += posoffset * rot;
// set the camera
llSetCameraParams([
CAMERA_ACTIVE, active,
CAMERA_BEHINDNESS_ANGLE, 0.0, //(0 to 180) degrees
CAMERA_BEHINDNESS_LAG, 0.0, //(0 to 3) seconds
CAMERA_DISTANCE, 0.0, //(0.5 to 10) meters
CAMERA_FOCUS, focus, //Region-relative position
CAMERA_FOCUS_LAG, 0.0 , //(0 to 3) seconds
CAMERA_FOCUS_LOCKED, TRUE, //(TRUE or FALSE)
CAMERA_FOCUS_THRESHOLD, 0.0, //(0 to 4) meters
CAMERA_POSITION, pos, //Region-relative position
CAMERA_POSITION_LAG, 1.0, //(0 to 3) seconds
CAMERA_POSITION_LOCKED, TRUE, //(TRUE or FALSE)
CAMERA_POSITION_THRESHOLD, 0.0, //(0 to 4) meters
CAMERA_FOCUS_OFFSET, ZERO_VECTOR //<-10,-10,-10> to <10,10,10> meters
]);
}

// these variables used to build a simple dialog as example of use
// of the camera. you can get key of what to watch however you
// want
list items;
list keys;
integer listener = -1;
integer channel = -1;

default
{
state_entry()
{
}
touch_start(integer total_number)
{
if(llDetectedKey(0)==llGetOwner())
llSensor("","",ACTIVE | PASSIVE,96,PI);
}
no_sensor()
{
llOwnerSay("nothing found");
}
sensor(integer n)
{
// build a simple list of names and keys of items we found
// and present in a dialog to owner
items = [];
keys = [];
integer i;
for(i=0;i<n;i++)
{
items += [llGetSubString(llDetectedName(i),0,11)];
keys += [llDetectedKey(i)];
}
if(listener == -1)
listener = llListen(channel,"","","");
llDialog(llGetOwner(),"\nWhat do you want to watch?",
["*Stop*"] + llList2List(items,0,10),channel);
}
listen(integer c,string n,key k,string m)
{
if(llGetOwnerKey(k)==llGetOwner())
{
llListenRemove(listener);
listener = -1;

if(m=="*Stop*")
{
// stop the camera
stop();
} else
{
integer i = llListFindList(items,[m]);
if(i!= -1)
{
// start the camera with the key of the object to watch
start(llList2Key(keys,i));
return;
}
}
}
}
// this routine needed in any script using this method of
// camera control
run_time_permissions(integer perm)
{
if(perm & PERMISSION_CONTROL_CAMERA)
{
controlling=TRUE;
setCamera(TRUE);
llSetTimerEvent(0.1);
}
}
// this routine needed in any script using this method of
// camera control
timer()
{
if(controlling)
setCamera(TRUE);
else
llSetTimerEvent(0.0);
}
}