Jump to content

Script controlled camera animation not smooth


MiranDMC

Recommended Posts

I'm trying to animate camera using SCM script. All calculated camera movements are smooth, as script code is called once peer each frame.

Problems starts when I try relate camera position or target position to any moving entity (actor, car, object...). Then camera still moves smoothly but there is noticeable jumping/shaking visible on the entity itself.

The relative camera/entity position changes like every other frame(?).

 

Here is test script:
 

{$CLEO .cs}
{$USE CLEO}

wait 1000

// set player position
08C7: put_actor $PLAYER_ACTOR at 2488.0 -1666.0 14.0 dont_warp_gang
0860: link_actor $PLAYER_ACTOR to_interior 0
04BB: select_interior 0

// set camera position
0930: lock_camera_position false
015F: set_camera_position 2488.0 -1666.0 14.0 rotation 0.0 0.0 0.0

092F: lock_camera_target_point false

// spawn car
0247: load_model 412 // request
038B: load_requested_models // force load
00A5: 0@ = create_car 412 at 2470.0 -1660.0 14.0
0249: release_model 412
07CC: set_player $PLAYER_CHAR can_enter_exit_vehicles true

while true
    wait 0
 
    00A0: store_actor $PLAYER_ACTOR position_to 1@ 2@ 3@      
    
    // read pos from actor's matrix
    /*0A96: 0@ = ped $PLAYER_ACTOR struct
    0@ += 0x14 // CMatrixLink*
    0A8D: 0@ = read_memory 0@ size 4 virtual_protect 0 // read pointer
    0@ += 0x30 // offset to positon vector
      
    0A8D: 1@ = read_memory 0@ size 4 virtual_protect 0 // read pos X
    0@ += 4
    
    0A8D: 2@ = read_memory 0@ size 4 virtual_protect 0 // read pos Y
    0@ += 4
    
    0A8D: 3@ = read_memory 0@ size 4 virtual_protect 0 // read pos Z
    0@ += 4*/
    
    
    0AD1: show_formatted_text_highpriority "X: %f~n~Y: %f~n~Z: %f" time 100 1@ 2@ 3@
    0160: set_camera_point_at 1@ 2@ 3@ switchstyle 2 // jump cut
end

 

I could imagine there are some delays between get entity position and setting camera coordinates, like for example requested camera position might be actually applied on next render frame.

But in this case there would be just noticeable constant delay-offset growing with entity speed.

Final result is different: when CJ is running horizontally to the camera there is visible silhouette around him, like he is rendered twice. This suggests that get position or set position function somehow sometimes obtains\sets data from previous frame, and sometimes it works immediately.

I tried to move "wait 0" command before and after coded block, but without success.

 

Yes I'm aware there are build in opcodes allowing to attach target/camera to entity but I like to implement camera animation with script code.

Edited by MiranDMC
Link to comment
Share on other sites

 

20 hours ago, MiranDMC said:

Final result is different: when CJ is running horizontally to the camera there is visible silhouette around him, like he is rendered twice.

 

No sorry, i didn't noticed a silhouette. I placed the scene infront of a white wall for better observing.

Spoiler
08C7: put_actor $PLAYER_ACTOR at 2057.5 -2248.6 13.6 dont_warp_gang
01B6: set_weather  1
00C0: set_current_time 12 0
015F: set_camera_position 2071.5 -2244.2 13.5 rotation 0.0 0.0 0.0

 

 

Maybe i need new glasses, but i couldn't see any annoying graphical effect

Your effect can be caused by graphic hardware, graphic software, game graphic enhancements
Have you tried opcode 0159:
 

04C4: create_coordinate 11@ 12@ 13@ from_actor $PLAYER_ACTOR offset  0.0 3.0  2.5
015F: set_camera_position 11@ 12@ 13@ rotation 0.0 0.0 0.0            
0159: camera_on_ped $PLAYER_ACTOR mode 15 switchstyle 2

 

or opcode 067C:

067C: put_camera_on_actor $PLAYER_ACTOR with_offset 0.0 1.7 1.5 rotation 0.0 0.0 0.6 0.0 2

 

 

 

Link to comment
Share on other sites

The effect for sure is not graphical. Problem is clearly lag between camera position and actual/rendered ped position. For me it looks like camera's coordinates are updated every 2nd frame, that's why CJ is rendered twice. Additionally the position lags at least one frame.
 

{$CLEO .cs}
{$USE CLEO}

wait 1000

// set player position
08C7: put_actor $PLAYER_ACTOR at 2488.0 -1666.0 14.0 dont_warp_gang
0860: link_actor $PLAYER_ACTOR to_interior 0
04BB: select_interior 0

// spawn car
0247: load_model 412 // request
038B: load_requested_models // force load
00A5: 0@ = create_car 412 at 2470.0 -1660.0 14.0
0249: release_model 412
07CC: set_player $PLAYER_CHAR can_enter_exit_vehicles true

// spawn basket ball object
cleo_call @SPAWN_HELPER_OBJECT args 0 result 20@

21@ = false // debug mode


while true
    // proces backspace key debug mode toggle
    if
        is_key_pressed 0x08 // backspace
    then
        if
            21@ == true
        then
            21@ = false
            015A: restore_camera   
        else
            21@ = true
        end
        
        // wait for key release
        while is_key_pressed 0x08 // backspace
            wait 0
        end
    end
    
    // get position
    cleo_call @ACTOR_GET_BONE_POS args 2 $PLAYER_ACTOR 6 result 1@ 2@ 3@ // get head position  
    //00A0: store_actor $PLAYER_ACTOR position_to 1@ 2@ 3@ // get spine position
    
    // set ball position
    0815: put_object 20@ at 1@ 2@ 3@ and_keep_rotation 
    
    // set camera position
    if
        21@ == true
    then
        015F: set_camera_position 1@ 2@ 3@ rotation 0.0 0.0 0.0
        0160: set_camera_point_at 2470.0 -1660.0 14.0 switchstyle 2 // jump cut
    end
        
    wait 0
end


// arg 0 - actor handle
// arg 1 - bone id
// return (float)(float)(float) world position x y z
:ACTOR_GET_BONE_POS
    0A96: 0@ = actor 0@ struct
    0AC7: 6@ = var 2@ offset // vector 3d pointer
    0AA6: call_method 0x5E4280 struct 0@ num_params 3 pop 0 1 1@ 6@ // CPed::GetBonePosition(RwV3d& outPosition, unsigned int boneId, bool updateSkinBones)
cleo_return 3 2@ 3@ 4@


// spawn object
// return - created object handle
:SPAWN_HELPER_OBJECT
    0247: load_model 2114 // request
    038B: load_requested_models // force load
    029B: 2@ = create_object 2114 at 0.0 0.0 0.0
    0249: release_model 2114
    
    01C7: remove_object_from_mission_cleanup_list 2@
    0382: set_object 2@ collision_detection false
    07F7: set_object 2@ indestructible true
    09CA: set_object 2@ immunities BP true FP true EP true CP true MP true  
    0392: make_object 2@ moveable 0   
cleo_return 1 2@ 

New script for tests. Now the camera position is placed on ped's head. I also added test object which is placed and the position in loop too.
Use BACKSPACE key to toggle camera placement.

Now it is easier to spot camera and object placement lagging.

Enter the car and drive it. First person view will be jumpy, and from external view it is visible that the ball object lags to follow.

 

I checked with IDA and script processing is called in same function as scene rendering. Checking frame counter delta in script always results in "1". I tried to animate camera more directly after NOPing camera processing and writing my own coords to memory. Same results.

 

I do not want to use attach_camera_to_X opcodes as I try to animate cameras with interpolation between car related to ped related view.

 

 

BTW. Disabling frame limiter reduces the lag, so maybe that's why you do not see the effect.

Edited by MiranDMC
Link to comment
Share on other sites

Dot Shee lan

How to create a Elevator ( a Lift ) using a script that like this script 

 

 

 

{$CLEO .cs}
{$USE CLEO}

thread 'Lift'


0247: load_model 1000 // request

:01
wait 0
if and
player.Defined($PLAYER_CHAR)
0102:   actor $PLAYER_ACTOR in_sphere 67.79 51.96 0.4 radius 1.2 1.2 3.0 sphere 1 stopped_on_foot
jf @01


038B: load_requested_models // force load
029B: 2@ = create_object 1000 at 67.79 51.96 0.4
0177: set_object 2@ Z_angle_to 90.0
0382: set_object 2@ collision_detection true
07F7: set_object 2@ indestructible true
09CA: set_object 2@ immunities BP true FP true EP true CP true MP true  
0392: make_object 2@ moveable 1 

034E: move_object 2@ to 67.79 51.96 100.609375 speed 1.0 1.0 1.0 collision_check 1





0249: release_model 1000



jump @01

 

 

spacer.png

Link to comment
Share on other sites

On 5/13/2023 at 10:28 PM, MiranDMC said:

Then camera still moves smoothly but there is noticeable jumping/shaking visible on the entity itself.

i only have these two from End of the Line Chapter 3.. is it useful for you?

 

0936: set_camera 2376.824 2141.102 36.2586 position_to 2399.813 2141.147 36.5957 time 2900 smooth_transition 0 
0920: point_camera 2377.82 2141.104 36.1737 transverse_to 2400.809 2141.149 36.5108 time 2900 smooth_transition 0 
Link to comment
Share on other sites

I figured it out. Seems it can not be done in script as scripts are processed too late in whole peer-frame code inside the game.

 

I created ASI plugin that had same jumping behaviour and it get fixed by calling `TheCamera.Process()`.

Same function can be also called via script, but it not gives desired effect, because as mentioned it is already to late for it then.

Edited by MiranDMC
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.