Jump to content

Dynamic camera for vehicle script


Sunbleached
 Share

You are about to reply to a thread that has been inactive for 1744 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hello! I need to add a dynamic camera to the vehicle script. How to do it? When I just add the parameters I get an error Script trying to set camera parameters but PERMISSION_CONTROL_CAMERA permission not set!

Thats the vehicle camera i have: llSetCameraEyeOffset(<-10.0, 1.0, 3.0>); llSetCameraAtOffset(<0, 1.0, 0>); (Do I need to keep it?).

I need to make it:

llSetCameraParams([CAMERA_ACTIVE, TRUE,
        CAMERA_BEHINDNESS_ANGLE, 24.00,
        CAMERA_BEHINDNESS_LAG, 0.10,
        CAMERA_DISTANCE, 5.00,
        CAMERA_PITCH, 18.00,
        CAMERA_POSITION_LAG, 0.00,
        CAMERA_POSITION_THRESHOLD, 0.00,
        CAMERA_POSITION_LOCKED, FALSE,
        CAMERA_FOCUS_LAG, 0.00,
        CAMERA_FOCUS_THRESHOLD, 0.00,
        CAMERA_FOCUS_LOCKED, FALSE,
        CAMERA_FOCUS_OFFSET, <0.0, 0.0, 0.0>
        ]);

What did i missed?

 

Edited by Sunbleached
Link to comment
Share on other sites

Apparently,  you missed requesting PERMISSION_CONTROL_CAMERA.  I suggest doing that when the driver sits down, as part of your startup sequence. Remember that you will need a run_time_permissions event to put your camera control parameters in. If you are doing other things that require permissions,  like triggering an animation,  you can bundle them in the same operation. 

Edited by Rolig Loon
  • Thanks 1
Link to comment
Share on other sites

21 minutes ago, Rolig Loon said:

Apparently,  you missed requesting PERMISSION_CONTROL_CAMERA.  I suggest doing that when the driver sits down, as part of your startup sequence. 

Thanks very much! I just added following lines to start up process and no errors now!

   else if((llGetPermissions() & PERMISSION_CONTROL_CAMERA))
    {
        llClearCameraParams();
        llSetCameraParams([CAMERA_ACTIVE, TRUE,
        CAMERA_BEHINDNESS_ANGLE, 0.000,
        CAMERA_BEHINDNESS_LAG, 0.10,
        CAMERA_DISTANCE, 8.29,
        CAMERA_PITCH, 7.000,
        CAMERA_POSITION_LAG, 0.00,
        CAMERA_POSITION_THRESHOLD, 0.00,
        CAMERA_POSITION_LOCKED, FALSE,
        CAMERA_FOCUS_LAG, 0.00,
        CAMERA_FOCUS_THRESHOLD, 0.00,
        CAMERA_FOCUS_LOCKED, FALSE,
        CAMERA_FOCUS_OFFSET, <0.0, 0.0, 0.0>
        ]);
        }

Link to comment
Share on other sites

I fixed it! Added lines:

llRequestPermissions(avatar, PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION | PERMISSION_CONTROL_CAMERA);

run_time_permissions(integer perms) {
if(perms & (PERMISSION_TAKE_CONTROLS | PERMISSION_CONTROL_CAMERA))

Link to comment
Share on other sites

1 hour ago, Sunbleached said:

I fixed it! Added lines:

llRequestPermissions(avatar, PERMISSION_TAKE_CONTROLS | PERMISSION_TRIGGER_ANIMATION | PERMISSION_CONTROL_CAMERA);

run_time_permissions(integer perms) {
if(perms & (PERMISSION_TAKE_CONTROLS | PERMISSION_CONTROL_CAMERA))

you are definitely improving your understanding. Good on you!

a little suggestion tho with testing for permissions. Is best to test for them individually. As when you combine them with OR in a single test then the result will be TRUE when either is TRUE

Example

PERMISSION_TAKE_CONTROLS = FALSE

PERMISSION_CONTROL_CAMERA = TRUE

means that: perms &  (PERMISSION_TAKE_CONTROLS | PERMISSION_CONTROL_CAMERA) will resolve to TRUE when PERMISSION_TAKE_CONTROLS is FALSE. Which can cause your script to act on a false positive, and will generate a permission not set! error when the script tries to llTakeControls()

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Advanced hints:

During a region crossing, you lose permissions momentarily. After the CHANGED_REGION event, there may be a period during which you don't have permissions in the new sim yet. You can see this with llGetPermissions. It's useful to check.

When you get the permissions back on region crossing completion, it's useful to reset the camera parameters and animations. Sometimes they are lost during a region crossing and need to be reset. If you see a messed-up camera or the avatar out of position on a working vehicle after a region crossing, that's often the problem. (If the camera or avatar rubber-bands back, that's a different problem. If the avatar separates from the vehicle completely, that's a failed region crossing. They're all separate bugs.)

 

  • Thanks 3
Link to comment
Share on other sites

25 minutes ago, Sunbleached said:

@animats

Hello! Thanks very much for your hint! Yes, it happens sometimes. Could you give a little more detail on what to do, please? (camera and position both)

In the "changed" event, when you get a CHANGED_REGION event, the script and its vehicle have completed the region crossing. The avatars and attachments may still be catching up. So on a CHANGED_REGION, set a flag like "region_cross_incomplete".

In your timer or control event, which is executed frequently, check that flag. If it's set, call llGetPermissions and see if you have all your permissions. If not, don't do anything; the avatars are still crossing the region boundary. If you have all your perms, reset the camera, sounds, and animations, the same way you got them started at startup, and clear the flag. This fixes the "camera lost position" and "avatar animation lost" problems. It's a SL bug that you need to do this.

Robust region crossing requires active management in vehicle scripts. I've written about this before. Other things to handle include:

  • Slowing down to avoid double region crossings.
  • Avatar is slow catching up with the vehicle. This is what the perms issue above comes from. (Sometimes the avatar never catches up at all, and the region crossing fails. Sometimes the avatar gets there first, and appears in a bogus position because it is a child prim, with coords relative to the vehicle. This either rubber-bands back quickly when the vehicle shows up, or leads to a failed region crossing.)
  • Dealing with the "sinking" problem when off the edge of the sim but the region crossing hasn't started yet. (Region crossings start when you're about 1m beyond the sim edge. "Sinking" comes from loss of support from the region being left, before the region being entered has taken over.)
  • Correcting unwanted changes in direction and speed when crossing a sim boundary. Easy to fix; force the last good velocity and omega vectors from the old sim using llSetVelocity and llSetAngularVelocity.

Most of the better vehicles in SL do some of these things. I seem to be the only builder who writes it up. I've written about this before.

This is reasonably hard to get right. I had to drive about 1000km in SL to debug.

  • Thanks 1
Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1744 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...