Jump to content

Need help scripting the camera position / orientation


Elexis Reinard
 Share

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

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

Recommended Posts

Hello!

Thank you for opening my postt!

I'm desperately trying to have a hud button (basic prim) to position the camera relatively to my avatar. I actually want this button to place the camera in a "pre-programmed" location and that faces the avatar in a constant way. Imagine "mugshots": They're always taken with the same frame, distance, etc.

So I've made my hud button and put a script based on some hours of googling (nb I have no IT background, don't flame me please :)

 

 

default
{
    state_entry()
    {
    }

    touch_start(integer total_number)
    {
        llRequestPermissions(llGetOwner(), PERMISSION_CONTROL_CAMERA | PERMISSION_ATTACH | PERMISSION_TRACK_CAMERA );

        llOwnerSay("Mughshot position!");
        
        llSetCameraParams([
            CAMERA_ACTIVE, 1, // 1 is active, 0 is inactive
            CAMERA_BEHINDNESS_ANGLE, 0.0, // (0 to 180) degrees
            CAMERA_BEHINDNESS_LAG, 0.0, // (0 to 3) seconds
            CAMERA_DISTANCE, 1.0, // ( 0.5 to 10) meters
            //CAMERA_FOCUS, <0.0,0.0,5.0>, // region relative position
            CAMERA_FOCUS_LAG, 0.01 , // (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 <0.0,0.0,0.0>, // region relative position
            CAMERA_POSITION_LAG, 0.1, // (0 to 3) seconds
            CAMERA_POSITION_LOCKED, FALSE, // (TRUE or FALSE)
            CAMERA_POSITION_THRESHOLD, 0.0, // (0 to 4) meters
            CAMERA_FOCUS_OFFSET, <0,0,1> // <-10,-10,-10> to <10,10,10> meters
        ]);
    }
}

 

 

Well, the text outputs properly, the camera seems to move (sometimes I have to press escape, click again, but it ends up reacting). So, it's good, but I'm stuck now. Altering CAMERA_FOCUS_OFFSET gives some control over the position of the camera, but I'm not very successful at this :(

I can't get the camera "look" into a specific direction. I would like to do the following:

- Make the camera face the player (no angle, just facing it).

- "attach" the camera to the avatar, so that it's placed always at the same angle. Now, when moving left/right, there's like a threshold under which the camera doesn't move. Being able to obtain the exact same angle is very important.

Thanks in advance for your help!

Link to comment
Share on other sites

The parameters you have written should give you the result you wanted.  You might set CAMERA_BEHINDNESS_LAG to 0.0 so that there's absolutely no delay in response as you move.  Other than that, the only thing I can suggest is that the parameter list really should be in a run_time_permissions event instead of your touch_start event..  That is ...

run_time_permissions(integer perm)

{

     if (perm & PERMISSION_CONTROL_CAMERA)

     {  //Do stuff}

}

In practice, it shouldn't make any difference since permission is granted automatically when you sit on or attach the scripted object.  Still, it's never a good idea to assume that any requested permission has been granted.

Link to comment
Share on other sites

You should consider another solution if your goal is to have a fixed camera position, angel and distance to look at your avatar.

I would like to point out how you set Camera Offsets in the SL Viewer 2.4 (current standard viewer)
No need for a script.
The settings will be used until you change them or you update the viewer.

First select Show Debug Settings from the menu:

Debug Settings.jpg

Then go to the Camera Offset you want to set:

Camera Offsets.jpg

This was my contribution to the Improving Your SL Experience With Better Camera Placement discussion in the old forum
Torley Linden made a very good

about these settings. Finally I refound it:)
  • Like 1
Link to comment
Share on other sites

 


- Make the camera face the player (no angle, just facing it).

- "attach" the camera to the avatar, so that it's placed always at the same angle. Now, when moving left/right, there's like a threshold under which the camera doesn't move. Being able to obtain the exact same angle is very important.

 

If by "face the player" you mean head-on, from the front, and by "'attaching'" you mean the cam should move smoothy backwards as the avatar walks forward... well, I'd be interested in any scripted cam that can do this, too.

You certainly can get the scripted cam to look back at your avatar from a particular angle in front, but then things get ugly when the avatar moves.  It's possible to track the avatar's motion from a fixed cam location in front (which is kind of fun, but not what you want), or it's possible to very jerkily hop the camera back a couple times a second to restore the desired position and viewing angle relative to the avatar's front, but I've never found a way to use the scripted cam to make that motion smooth, as it can be for behind-avatar tracking.  (What I'm describing is more or less what one sees when walking the avatar backwards with the down arrow key... which, with a little practice, is usable for machinima.)

I would love to be proven wrong about that.

[ETA: What I'm describing is equivalent to a CameraOffsetRearView debug setting with a positive X value.]

Link to comment
Share on other sites

Hey,

Thanks all for your help already!

This camera debug values certainly is promising. It's however centered on the middle of the body. Increasing the height of the camera also makes it rotate downards, like to keep the body's center of mass in the middle of the screen.

Is it possible to force the camera to "look" at a certain body part?

The need here is to be able to get two exact same screenshots of the character's body parts. With the screenshots in gimp, I would "cut" the different versions of the parts (big nose, piggy nose, mustache, no mustache, etc.) and then have a collection of parts to chose from in order to "paste" them on a "blank" face. This is why I try to lock the camera to be able to make more variations later on.

(I offered some help to my friend who makes an iphone game, I came with this idea to get a "character customization" library easily with SL)

If you know any way to solve this :-)

Thanks again!

Link to comment
Share on other sites

 


Elexis Reinard wrote:

This camera debug values certainly is promising. It's however centered on the middle of the body. Increasing the height of the camera also makes it rotate downards, like to keep the body's center of mass in the middle of the screen.

Is it possible to force the camera to "look" at a certain body part?

Yes, there are corresponding debug settings to control where the camera is pointing at. FocusOffset[Front/Rear/Group]View

 

  • Like 2
Link to comment
Share on other sites

  • 1 month later...

Take a look at this thread I made about fixing the SL camera placement for standard use. It explains the two debug settings you need to change in order to move the camera and have it look in a specific direction.

In addition to CameraOffset there is also a FocusOffset. Think of them like two tacks on a corkboard with a string tied between them. One tack representing the camera, one representing where the camera is looking. If you only move the camera tack it will be impossible to get the camera to actually look where you want from a good angle. So if you want the camera to look at a specific body part, you need to adjust both to bring that body part into view between the camera and its focus.

The camera placement presets Dora suggests are a good idea if you only need one or two. These are only present in Viewer 2 as Viewer 1 had only the single camera position. In viewer 2 the preset locations are RearView, FrontView and GroupView.

RearView is your default "behind the avatar" camera view. I recommend not changing this except to improve the camerra placement as described in the thread I linked. (And I do recommend making that change, it's a vast improvement.) The other two can be used as presets for any purpose you need. Use CameraOffset to move the camera to where you'll need it. Use FocusOffset to face the camera in the direction of the body part you want to view.

You can access the presets easily from the "View" menu accessed via the toolbar, so once set you can easily switch between the camera views you have set up.

I'm hoping in the future we have a broader selection of camera presets we can play with.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4703 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...