Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

objects that follow your camera?

Jay Edelbrock
Registered User
Join date: 19 Feb 2005
Posts: 19
11-17-2005 22:30
ok, so earlier today, someone showed me a little helicopter that would follow your camera around. what I'm wondering, is how would one go about making something like this?
Cid Jacobs
Theoretical Meteorologist
Join date: 18 Jul 2004
Posts: 4,304
11-18-2005 00:40
Camera Follower
Hope that helps :}
_____________________
Jay Edelbrock
Registered User
Join date: 19 Feb 2005
Posts: 19
11-18-2005 01:31
yes, that does help, now that I've figured most of what I want it to do out on my own ;)

one last thing, what would I use in place of llSetRot if I want to make it turn and face me?


oh, here's my code so far:

vector pos;
rotation rot;
default
{
state_entry()
{
vector pos = llGetPos();
llSetStatus(STATUS_PHYSICS, TRUE);
llSleep(0.1);
llMoveToTarget(pos,0.1);
key id = llGetOwner();
llSensorRepeat("","",AGENT,200000,7000*PI,.4);
llRequestPermissions(id, PERMISSION_TRACK_CAMERA);

}

sensor(integer total_number)
{
pos = llGetCameraPos();
rot = llGetCameraRot();
llMoveToTarget(pos,.3);
llSetRot(rot);
}
}


it all works, except for the llSetRot part. Any suggestions...?
Senuka Harbinger
A-Life, one bit at a time
Join date: 24 Oct 2005
Posts: 491
11-18-2005 08:15
From: Jay Edelbrock
yes, that does help, now that I've figured most of what I want it to do out on my own ;)

one last thing, what would I use in place of llSetRot if I want to make it turn and face me?


oh, here's my code so far:

vector pos;
rotation rot;
default
{
state_entry()
{
vector pos = llGetPos();
llSetStatus(STATUS_PHYSICS, TRUE);
llSleep(0.1);
llMoveToTarget(pos,0.1);
key id = llGetOwner();
llSensorRepeat("","",AGENT,200000,7000*PI,.4);
llRequestPermissions(id, PERMISSION_TRACK_CAMERA);

}

sensor(integer total_number)
{
pos = llGetCameraPos();
rot = llGetCameraRot();
llMoveToTarget(pos,.3);
llSetRot(rot);
}
}


it all works, except for the llSetRot part. Any suggestions...?



quick and dirty way to calculate the rotation of the camera assuming the object *is* following the camera would be to get the position of the object and the position of the owner, subtract the position of the object from the position of the owner to get a vector that looks from the object to the owner. (lets call it vectolookat), then set your rotation amount to be equal to llRotBetween(<0,0,1>,vectolookat);

you would probabl have to sensor for the owner's specific key it order for this to work.

also as a note, the maximum distance a sensor will work is 96m, and a full sphere is PI (because it's not measuring a single arc sweep starting from the +x to the +y but doing a arc sweep from +x to +y *and* -y axis)
Jay Edelbrock
Registered User
Join date: 19 Feb 2005
Posts: 19
11-18-2005 11:38
hmm.... but wouldnt that make it face the avatar, and not where the camera is facing? Oh, and I put an llSetText to display the rotation, and it *is* getting the correct rotation, it just isnt actually turning. I guess what my question is, what function do I need to use instead of llSetRot?
Harris Hare
Second Life Resident
Join date: 5 Nov 2004
Posts: 301
11-18-2005 11:46
To rotate physical objects, you need to use llRotLookAt().
Jay Edelbrock
Registered User
Join date: 19 Feb 2005
Posts: 19
completed script.
11-19-2005 03:20
vector pos;
rotation rot;
default
{
on_rez(integer start_param)
{
llResetScript();
}
state_entry()
{
vector pos = llGetPos();
llSetStatus(STATUS_PHYSICS, TRUE);
llSleep(0.1);
llMoveToTarget(pos,0.1);
key id = llGetOwner();
llRequestPermissions(id, PERMISSION_TRACK_CAMERA);
llSitTarget(<0,0,0>, ZERO_ROTATION);


}

changed(integer change) {
if (change & CHANGED_LINK) {
key avatar = llAvatarOnSitTarget();

if (avatar) {
llUnSit(avatar);

llPushObject(avatar, <0.0, 0.0, 10.0>, ZERO_VECTOR, FALSE);
}
}
}
run_time_permissions(integer perm)
{
if (perm & PERMISSION_TRACK_CAMERA)
{
llSetTimerEvent(0.4);
}
}
timer()
{
pos = llGetCameraPos();
pos = pos + <0,0,.5>;
llMoveToTarget(pos,.3);
rot = llGetCameraRot();
llRotLookAt(rot,1,.1);
}
}


I added a few things, such as a little bit that keeps people from sitting on my camera, and cleaned up the script to run a little faster. after playing around with it in the sandbox, the only problem I had was throwing it out into the void, and getting it back in my lost and found, hehe. Oh, and props to Dirty McLean for helping me so much with this in game