Jump to content
LeonissiaLoc

Remote Camera Follow Moving Prim Vehicle

Recommended Posts

How can I make my camera lock focus behind an rc helicopter? I want to wear a hud that has a button I press to activate the camera to follow the RC heli remotely. Any help will be appreciated, Thank you.

Share this post


Link to post
Share on other sites

As far as I know LSL only allows you to change the camera view of an AV when they sit on a Prim ... and then only offsets etc in relation to the AV. I do not think you can force it to focus on a specific object so that it follows after that. The only semi-solution (and would be extremely complicated (at least for me) would be for there to be communications between the RC heli and the prim that the AV is seated on that calculates the offset based on the position of the RC heli in relation to the prim that AV is seated on.

Share this post


Link to post
Share on other sites

Afraid I have to concur: there's no acceptable solution here, or at least none that I ever found. It is possible for a script in the HUD to keep track of where the RC helicopter object is (inside or very near the region where the HUD is being worn) and then for it to control the cam position and focus to follow that object but only by continuously updating those parameters -- and jittery network latency between script and viewer insures that this won't look all that continuous

That is very different and very much "jumpier" than the viewer-internal cam tracking that automatically smoothly follows objects you're looking at as they move. I never found a way for a script to trick the viewer into following what I wanted it to follow, and I've never seen it done successfully, but maybe it's possible.

Share this post


Link to post
Share on other sites

Agreed, I have an RC vehicle project on the back burner for the same reason. My attempt at a workaround is to have the pilot sit on it like  normal vehicle and ask that they remove all attachments and wear an alpha mask layer. It's far from ideal and raises a lot of other problems in the process (like the avatar's physics shape getting added to the linkset and is in this case larger than the RC vehicle).

There is a bit of a silver lining though. Several feature requests for expanding the scripted camera have been accepted on the JIRA. BUG-40473 specifically requested the ability for the camera to follow an object. That was marked as a duplicate to I believe BUG-6325 which suggests several additional enhancements to llSetCameraParams - and that has been marked as accepted. So hopefully one day this will get priority. :)

Share this post


Link to post
Share on other sites
Posted (edited)
5 hours ago, LeonissiaLoc said:

How can I make my camera lock focus behind an rc helicopter? I want to wear a hud that has a button I press to activate the camera to follow the RC heli remotely. Any help will be appreciated, Thank you.

Do you mean something like this?

https://marketplace.secondlife.com/p/Camera-Focus-lock-view-on-an-object-and-follow-it/4662958

(There also is a full-permissions version for creators in Related section)

Edited by Alyona Su

Share this post


Link to post
Share on other sites
2 hours ago, Qie Niangao said:

Afraid I have to concur: there's no acceptable solution here, or at least none that I ever found. It is possible for a script in the HUD to keep track of where the RC helicopter object is (inside or very near the region where the HUD is being worn) and then for it to control the cam position and focus to follow that object but only by continuously updating those parameters -- and jittery network latency between script and viewer insures that this won't look all that continuous

That is very different and very much "jumpier" than the viewer-internal cam tracking that automatically smoothly follows objects you're looking at as they move. I never found a way for a script to trick the viewer into following what I wanted it to follow, and I've never seen it done successfully, but maybe it's possible.

I managed to script a drone a few years ago that did exactly that.  A timer updated the drone's position and thus the cam position once a second.  It did mean that the camera view was jumpy if the drone was moving fairly quickly, but it made a great drone for remote surveilance if you parked it or moved it around short distances at a time.  It's a matter of adjusting your expectations.  ;)

  • Like 2

Share this post


Link to post
Share on other sites
Posted (edited)

Will this bit of code communicate to the helicopter from the hud script? I'm not worried if any of the solutions are jerky or not because that can be improved, Thanks.

focus_on_helicopter()
{

    vector here = llGetPos();
    llSetCameraParams([CAMERA_ACTIVE, TRUE,
        CAMERA_BEHINDNESS_ANGLE, 0.0,
        CAMERA_BEHINDNESS_LAG, 0.5,
        //CAMERA_DISTANCE, 4.0,
        CAMERA_DISTANCE, 6.0,
        CAMERA_PITCH, 10.0,
        // CAMERA_FOCUS,
        CAMERA_FOCUS_LAG, 0.05,
        CAMERA_FOCUS_LOCKED, FALSE,
        CAMERA_FOCUS_THRESHOLD, 0.0,
        // CAMERA_POSITION,
        CAMERA_POSITION_LAG, 0.5,
        CAMERA_POSITION_LOCKED, FALSE,
        CAMERA_POSITION_THRESHOLD, 0.0,
        //CAMERA_FOCUS_OFFSET, <0,0,3>];
        CAMERA_FOCUS_OFFSET, <0,0,0>]);
}

This is the Script in the Heli:

default{
    on_rez(integer r){
        llResetScript();
    }
     state_entry()
    {
        llListen(3, "","", ""); 
    }
    listen(integer channel, string name, key id, string message)
    {
         if (llGetOwner() != llGetOwnerKey(id))
        {return;}
        
        if(message == "on")
        {
          llSetTimerEvent(0.05);
        }
          
        if (message == "off")  
        {
            llSetTimerEvent(0.0);   
        }
        
        }
 timer()
    {
      llRegionSay(4,(string)llGetPos()); 
    }
}

 

Edited by LeonissiaLoc

Share this post


Link to post
Share on other sites
Posted (edited)

@LeonissiaLoc There is no real communication needed between the two objects.

For example, I have a nondescript object moving around in a circle (1 degree every 0.022 seconds). It only has code for moving itself, it does not listen or send messages.

I then have this script in a worn attachment (also updating the camera params every 0.022 seconds, but you do not need to do it this often):

key uuid = "c6e3e94d-9586-ff64-2f52-bae2b76a25b9";

default
{
    state_entry()
    {
        llRequestPermissions(llGetOwner(), PERMISSION_CONTROL_CAMERA);
    }

    run_time_permissions(integer perm)
    {
        llSetTimerEvent(0.022);
    }

    timer()
    {
        // Get the remote object's position and rotation.
        list data = llGetObjectDetails(uuid, [OBJECT_POS, OBJECT_ROT]);
        vector pos = llList2Vector(data, 0);
        rotation rot = llList2Rot(data, 1);

        llSetCameraParams([
            // Begin controlling the camera and prevent it from being moved.
            // (Alt-cam will still override this.)
            CAMERA_ACTIVE, TRUE,
            CAMERA_FOCUS_LOCKED, TRUE,
            CAMERA_POSITION_LOCKED, TRUE,

            CAMERA_FOCUS, pos,                           // The position the camera will LOOK at.
            CAMERA_POSITION, pos + (<0, -2, 1> * rot)    // The position the camera will BE at.
        ]);
    }

    touch_start(integer n)
    {
        llClearCameraParams();
        llSetTimerEvent(0);
    }
}

Note that I used "<0, -2, 1>" as an offset so that the camera would be on the object's right side and slightly above it.

For testing purposes, you can select any object or link in Edit Mode and click on the "Copy Keys" button in the General tab of the Edit Tools window. If you were to rez an object with a script and wanted to track that instead, you could get the rezzed object's key through the object_rez event. For any other case, you'd require some kind of custom communication between the objects.

Also note: Because of the *_LOCKED values, the camera change will be instant, so this will always look jerky.

Edited by Wulfie Reanimator
  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, Wulfie Reanimator said:

@LeonissiaLoc There is no real communication needed between the two objects.

For example, I have a nondescript object moving around in a circle (1 degree every 0.022 seconds). It only has code for moving itself, it does not listen or send messages.

I then have this script in a worn attachment (also updating the camera params every 0.022 seconds, but you do not need to do it this often):


key uuid = "c6e3e94d-9586-ff64-2f52-bae2b76a25b9";

default
{
    state_entry()
    {
        llRequestPermissions(llGetOwner(), PERMISSION_CONTROL_CAMERA);
    }

    run_time_permissions(integer perm)
    {
        llSetTimerEvent(0.022);
    }

    timer()
    {
        // Get the remote object's position and rotation.
        list data = llGetObjectDetails(uuid, [OBJECT_POS, OBJECT_ROT]);
        vector pos = llList2Vector(data, 0);
        rotation rot = llList2Rot(data, 1);

        llSetCameraParams([
            // Begin controlling the camera and prevent it from being moved.
            // (Alt-cam will still override this.)
            CAMERA_ACTIVE, TRUE,
            CAMERA_FOCUS_LOCKED, TRUE,
            CAMERA_POSITION_LOCKED, TRUE,

            CAMERA_FOCUS, pos,                           // The position the camera will LOOK at.
            CAMERA_POSITION, pos + (<0, -2, 1> * rot)    // The position the camera will BE at.
        ]);
    }

    touch_start(integer n)
    {
        llClearCameraParams();
        llSetTimerEvent(0);
    }
}

Note that I used "<0, -2, 1>" as an offset so that the camera would be on the object's right side and slightly above it.

For testing purposes, you can select on any object or link in Edit Mode and click on the "Copy Keys" button in the General tab of the Edit Tools window. If you were to rez an object and wanted to track that instead, you could get the rezzed object's key through the object_rez event. For any other case, you'd require some kind of custom communication between the objects.

Thank you very much, this works as intended now.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...