Help Setting Player Camera Lock To A Point by X Y Z

Ramin_

New member
Joined
Aug 13, 2015
Messages
4
Reaction score
0
Hey guys sorry for my basic question but I'm really struggling as I found many many many stuffs online base codes functions etc I tried all and it was not what I wanted at all ! so I decided to ask help from an expert which respectfully is a lot of you guys here anyway lets get back to the problem

Task I want to achieve : Using memory manipulating I want to lock players camera at X Y Z point in world
Steps Iv done :
So until now I can get players current position using these memories which I add to gta_sa.exe
PLAYER_BASE_ADDRESS = 0xB6F5F0 # Base address for player data
XYZ_OFFSET = 0x14 # Offset to XYZ position structure
POSITION_X_OFFSET = 0x30 # Offset to X position
POSITION_Y_OFFSET = 0x34 # Offset to Y position
POSITION_Z_OFFSET = 0x38 # Offset to Z position

for example that will give something like that
Player Position: X = 686.7557983398438, Y = 888.8825073242188, Z = -39.41261672973633
In Cleo iv tested code snipped I got from this post
Screen Camera Look at Position(Multi-Purpose)- GET CAMERA FACING ANGLES
And This post
Need auto walk to ten cordinates
and I made a cleo which will accept /look x y z command and point the camera to that location using Sampfuncs that also works perfectly fine which ill share the code if you want
Thanks to @Parazitas
Code:
{$CLEO .cs}

// Initialize
0000:

// Wait for the game to fully load
REPEAT
    WAIT 0
UNTIL 0AFA: // Wait until SAMP is initialized

// Register the `/look` command in SA-MP
0B34: samp register_client_command "look" to_label @cmd_look

// Main loop (necessary for CLEO scripts)
WHILE TRUE
    WAIT 0
END

// Label triggered by the `/look` command
:cmd_look
    // Get the parameters (X, Y, Z) typed after `/look`
    0B35: samp 31@ = get_last_command_params
    
    // Scan the input for three float values (X, Y, Z)
    IF 0AD4: $NOT_USED = scan_string 31@ format "%f %f %f" 1@ 2@ 3@
    THEN
        // Set the camera to look at the specified coordinates (X, Y, Z)
        0AB1: @CAMERA_AT_POS 3 XYZ: 1@ 2@ 3@
    ELSE
        // If the input was invalid, show an error message
        0AF8: samp add_message_to_chat "{FF0000}Invalid format! Usage: /look X Y Z"
    END

    // Return to the game after handling the command
    0B43: samp cmd_ret

//0AB1: @AIM_AT_POS 3 XYZ: 1@ 2@ 3@
:CAMERA_AT_POS
0087: 8@ = 3@
068D: get_camera_position_to 3@ 4@ 5@
0063: 0@ -= 3@
0063: 1@ -= 4@
0604: get_Z_angle_for_point 0@ 1@ store_to 6@
6@ -= 90.0
0017: 6@ /= 57.2957795         
005B: 6@ += 8@  // (float)                         
0A8D: 7@ = read_memory 0xB6F248 size 4 virtual_protect 0
0A25: set_camera_on_players_X_angle 7@ Z_angle 6@
0661: "by Opcode.eXe | UGBASE.EU"
0AB2: 0
but the problem is with camera which I'm trying to manipulate the looking angle to the point I want in python (I'm not asking python code help)
no matter what code base address I tried CCamera or what ever I found like 10 in this forum and total net but its not what I want ! i mean some not even working for setting player camera
so may question is ! can any one guide me so how can I simply point and lock player camera look at a point using that point x y z coordinates using only memory hack not cleo not samp funcs nothing at all ?
 
Solution
as this was good to know stuff but it was way different than what I expected maybe I did something wrong or maybe it was different
basically its setting rotation but I want to point the camera at
as I told like this
Post
but not using cleo or stuff only want to get base address and offsets to set for camera which I don't find any
CameraXAngle(Float):
PHP:
0xB6F258
CameraYAngle(Float):
PHP:
0xB6F248
C++:
int addrof(CCamera::GetGameCamPosition) = ADDRESS_BY_VERSION(0x50AE50, 0, 0, 0, 0, 0);
int gaddrof(CCamera::GetGameCamPosition) = GLOBAL_ADDRESS_BY_VERSION(0x50AE50, 0, 0, 0, 0, 0);

CVector *CCamera::GetGameCamPosition() {
    return plugin::CallMethodAndReturnDynGlobal<CVector *, CCamera...

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
Old memory collection:
NOTE:
Rotation only will be set when actor is moving
PHP:
* CPed +0x558 = [float] Current rotation (Z angle)
This can be re-created without cleo, scroll below for more details
PHP:
:char_goto
{
0@ = X
1@ = Y
2@ = Z
3@ = state of sprint - TRUE or FALSE
0AB1: call @char_goto 4 XYZ 0@ 1@ 2@ sprint TRUE
}
repeat
   wait 0
   00A0: store_actor $PLAYER_ACTOR position_to 4@ 5@ 2@
   0063: 0@ -= 4@
   0063: 1@ -= 5@
   0604: get_Z_angle_for_point 0@ 1@ store_to 2@
   005B: 0@ += 4@
   005B: 1@ += 5@
   2@ *= 0.01745
   0A96: 4@ = actor $PLAYER_ACTOR struct
   4@ += 0x558
   0A8C: write_memory 4@ size 4 value 2@ virtual_protect 0
   if
       3@ == 0
   then
       4@ = 0xB73458
       4@ += 0x20
       0A8C: write_memory 4@ size 1 value 0 virtual_protect 0 // don't send sprint
       4@ = 0xB73458
       4@ += 0x3
       0A8C: write_memory 4@ size 1 value 255 virtual_protect 0 // send walk
   else
       4@ = 0xB73458
       4@ += 0x20
       0A8C: write_memory 4@ size 1 value 255 virtual_protect 0 // send sprint
       4@ = 0xB73458
       4@ += 0x3
       0A8C: write_memory 4@ size 1 value 255 virtual_protect 0 // send walk
   end 
until 00ED: actor $PLAYER_ACTOR 0 near_point 0@ 1@ radius 0.5 0.5 on_foot
0AB2: ret 0

C++:
// targetX = 0@ (Target X-coordinate)
// targetY = 1@ (Target Y-coordinate)
// targetZ = 2@ (Target Z-coordinate)

// Store the player's actor position (X, Y, Z) into variables 4@, 5@, and 2@ respectively
00A0: store_actor $PLAYER_ACTOR position_to 4@ 5@ 2@

// Calculate the difference in X and Y between the target and player
// Subtract the player's X position from the target's X position
0063: 0@ -= 4@   // targetX = targetX - playerX (difference in X position)
// Subtract the player's Y position from the target's Y position
0063: 1@ -= 5@   // targetY = targetY - playerY (difference in Y position)

// Get the Z angle (the angle between the player's position and the target on the X-Y plane)
// This will calculate the direction from the player to the target
0604: get_Z_angle_for_point 0@ 1@ store_to 2@   // 2@ will store the angle (in degrees)

// Restore the original values of 0@ and 1@ by adding back the player's X and Y coordinates
005B: 0@ += 4@   // Restore original targetX
005B: 1@ += 5@   // Restore original targetY

// Convert the angle in degrees (stored in 2@) to radians
// 1 degree = 0.01745 radians, so multiply the angle by this value
2@ *= 0.01745    // Convert Z angle to radians

// Get the actor's memory structure base address and store it in 4@
// The structure base address for the player actor is retrieved here
0A96: 4@ = actor $PLAYER_ACTOR struct   // Get player actor structure address into 4@

// Adjust 4@ by adding the offset 0x558, which is the memory address location where the actor's current rotation angle is stored
// This moves the address to the part of the memory where we can write the player's rotation (angle)
4@ += 0x558     // Move to the memory address where the rotation angle is stored

// Write the calculated Z angle (in radians, stored in 2@) to the player's memory address
// This will set the player's rotation to face the target point (by updating the rotation angle in memory)
0A8C: write_memory 4@ size 4 value 2@ virtual_protect 0   // Write the new Z angle (in radians) to memory

PHP:
M_PI = 3.1415926535897932384626433832795
0604: get_Z_angle_for_point 0@ 1@ store_to 2@ - below:
C++:
#include <iostream>
#include <cmath> // For atan2 and degrees conversion

// Function to calculate the Z angle (in degrees) between two points
void get_Z_angle_for_point(double x1, double y1, double x2, double y2, double &angle_degrees) {
    // Calculate the difference in x and y
    double delta_x = x2 - x1;
    double delta_y = y2 - y1;
 
    // Calculate the angle in radians using atan2
    double angle_radians = atan2(delta_y, delta_x);
 
    // Convert angle to degrees
    angle_degrees = angle_radians * (180.0 / M_PI);
}

int main() {
    // Points
    double x1 = 1.0, y1 = 2.0; // 0@
    double x2 = 4.0, y2 = 6.0; // 1@
 
    // Variable to store the Z angle
    double Z_angle; // 2@
 
    // Call the function to calculate the angle and store it in Z_angle
    get_Z_angle_for_point(x1, y1, x2, y2, Z_angle);
 
    // Output the result
    std::cout << "The Z angle (in degrees) between (" << x1 << ", " << y1 << ") and ("
              << x2 << ", " << y2 << ") is: " << Z_angle << "°" << std::endl;
 
    return 0;
}



Atan2
 
Last edited:

Ramin_

New member
Joined
Aug 13, 2015
Messages
4
Reaction score
0
Old memory collection:
NOTE:
Rotation only will be set when actor is moving
PHP:
* CPed +0x558 = [float] Current rotation (Z angle)
This can be re-created without cleo, scroll below for more details
PHP:
:char_goto
{
0@ = X
1@ = Y
2@ = Z
3@ = state of sprint - TRUE or FALSE
0AB1: call @char_goto 4 XYZ 0@ 1@ 2@ sprint TRUE
}
repeat
   wait 0
   00A0: store_actor $PLAYER_ACTOR position_to 4@ 5@ 2@
   0063: 0@ -= 4@
   0063: 1@ -= 5@
   0604: get_Z_angle_for_point 0@ 1@ store_to 2@
   005B: 0@ += 4@
   005B: 1@ += 5@
   2@ *= 0.01745
   0A96: 4@ = actor $PLAYER_ACTOR struct
   4@ += 0x558
   0A8C: write_memory 4@ size 4 value 2@ virtual_protect 0
   if
       3@ == 0
   then
       4@ = 0xB73458
       4@ += 0x20
       0A8C: write_memory 4@ size 1 value 0 virtual_protect 0 // don't send sprint
       4@ = 0xB73458
       4@ += 0x3
       0A8C: write_memory 4@ size 1 value 255 virtual_protect 0 // send walk
   else
       4@ = 0xB73458
       4@ += 0x20
       0A8C: write_memory 4@ size 1 value 255 virtual_protect 0 // send sprint
       4@ = 0xB73458
       4@ += 0x3
       0A8C: write_memory 4@ size 1 value 255 virtual_protect 0 // send walk
   end
until 00ED: actor $PLAYER_ACTOR 0 near_point 0@ 1@ radius 0.5 0.5 on_foot
0AB2: ret 0

C++:
// targetX = 0@ (Target X-coordinate)
// targetY = 1@ (Target Y-coordinate)
// targetZ = 2@ (Target Z-coordinate)

// Store the player's actor position (X, Y, Z) into variables 4@, 5@, and 2@ respectively
00A0: store_actor $PLAYER_ACTOR position_to 4@ 5@ 2@

// Calculate the difference in X and Y between the target and player
// Subtract the player's X position from the target's X position
0063: 0@ -= 4@   // targetX = targetX - playerX (difference in X position)
// Subtract the player's Y position from the target's Y position
0063: 1@ -= 5@   // targetY = targetY - playerY (difference in Y position)

// Get the Z angle (the angle between the player's position and the target on the X-Y plane)
// This will calculate the direction from the player to the target
0604: get_Z_angle_for_point 0@ 1@ store_to 2@   // 2@ will store the angle (in degrees)

// Restore the original values of 0@ and 1@ by adding back the player's X and Y coordinates
005B: 0@ += 4@   // Restore original targetX
005B: 1@ += 5@   // Restore original targetY

// Convert the angle in degrees (stored in 2@) to radians
// 1 degree = 0.01745 radians, so multiply the angle by this value
2@ *= 0.01745    // Convert Z angle to radians

// Get the actor's memory structure base address and store it in 4@
// The structure base address for the player actor is retrieved here
0A96: 4@ = actor $PLAYER_ACTOR struct   // Get player actor structure address into 4@

// Adjust 4@ by adding the offset 0x558, which is the memory address location where the actor's current rotation angle is stored
// This moves the address to the part of the memory where we can write the player's rotation (angle)
4@ += 0x558     // Move to the memory address where the rotation angle is stored

// Write the calculated Z angle (in radians, stored in 2@) to the player's memory address
// This will set the player's rotation to face the target point (by updating the rotation angle in memory)
0A8C: write_memory 4@ size 4 value 2@ virtual_protect 0   // Write the new Z angle (in radians) to memory

PHP:
M_PI = 3.1415926535897932384626433832795
0604: get_Z_angle_for_point 0@ 1@ store_to 2@ - below:
C++:
#include <iostream>
#include <cmath> // For atan2 and degrees conversion

// Function to calculate the Z angle (in degrees) between two points
void get_Z_angle_for_point(double x1, double y1, double x2, double y2, double &angle_degrees) {
    // Calculate the difference in x and y
    double delta_x = x2 - x1;
    double delta_y = y2 - y1;
 
    // Calculate the angle in radians using atan2
    double angle_radians = atan2(delta_y, delta_x);
 
    // Convert angle to degrees
    angle_degrees = angle_radians * (180.0 / M_PI);
}

int main() {
    // Points
    double x1 = 1.0, y1 = 2.0; // 0@
    double x2 = 4.0, y2 = 6.0; // 1@
 
    // Variable to store the Z angle
    double Z_angle; // 2@
 
    // Call the function to calculate the angle and store it in Z_angle
    get_Z_angle_for_point(x1, y1, x2, y2, Z_angle);
 
    // Output the result
    std::cout << "The Z angle (in degrees) between (" << x1 << ", " << y1 << ") and ("
              << x2 << ", " << y2 << ") is: " << Z_angle << "°" << std::endl;
 
    return 0;
}



Atan2
thanks alot for this amount of clarification and work you put I respect you thanks ill check and try to get it working ill definitely update you
 

Ramin_

New member
Joined
Aug 13, 2015
Messages
4
Reaction score
0
as this was good to know stuff but it was way different than what I expected maybe I did something wrong or maybe it was different
basically its setting rotation but I want to point the camera at
as I told like this
Post
but not using cleo or stuff only want to get base address and offsets to set for camera which I don't find any
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
as this was good to know stuff but it was way different than what I expected maybe I did something wrong or maybe it was different
basically its setting rotation but I want to point the camera at
as I told like this
Post
but not using cleo or stuff only want to get base address and offsets to set for camera which I don't find any
CameraXAngle(Float):
PHP:
0xB6F258
CameraYAngle(Float):
PHP:
0xB6F248
C++:
int addrof(CCamera::GetGameCamPosition) = ADDRESS_BY_VERSION(0x50AE50, 0, 0, 0, 0, 0);
int gaddrof(CCamera::GetGameCamPosition) = GLOBAL_ADDRESS_BY_VERSION(0x50AE50, 0, 0, 0, 0, 0);

CVector *CCamera::GetGameCamPosition() {
    return plugin::CallMethodAndReturnDynGlobal<CVector *, CCamera *>(gaddrof(CCamera::GetGameCamPosition), this);
}
C++:
int addrof(CCamera::UpdateAimingCoors) = ADDRESS_BY_VERSION(0x50CB10, 0, 0, 0, 0, 0);
int gaddrof(CCamera::UpdateAimingCoors) = GLOBAL_ADDRESS_BY_VERSION(0x50CB10, 0, 0, 0, 0, 0);

void CCamera::UpdateAimingCoors(CVector const *AimingTargetCoors) {
    plugin::CallMethodDynGlobal<CCamera *, CVector const *>(gaddrof(CCamera::UpdateAimingCoors), this, AimingTargetCoors);
}

 
Solution

Ramin_

New member
Joined
Aug 13, 2015
Messages
4
Reaction score
0
thanks alot my friend
CameraXAngle(Float):
PHP:
0xB6F258
CameraYAngle(Float):
PHP:
0xB6F248
C++:
int addrof(CCamera::GetGameCamPosition) = ADDRESS_BY_VERSION(0x50AE50, 0, 0, 0, 0, 0);
int gaddrof(CCamera::GetGameCamPosition) = GLOBAL_ADDRESS_BY_VERSION(0x50AE50, 0, 0, 0, 0, 0);

CVector *CCamera::GetGameCamPosition() {
    return plugin::CallMethodAndReturnDynGlobal<CVector *, CCamera *>(gaddrof(CCamera::GetGameCamPosition), this);
}
C++:
int addrof(CCamera::UpdateAimingCoors) = ADDRESS_BY_VERSION(0x50CB10, 0, 0, 0, 0, 0);
int gaddrof(CCamera::UpdateAimingCoors) = GLOBAL_ADDRESS_BY_VERSION(0x50CB10, 0, 0, 0, 0, 0);

void CCamera::UpdateAimingCoors(CVector const *AimingTargetCoors) {
    plugin::CallMethodDynGlobal<CCamera *, CVector const *>(gaddrof(CCamera::UpdateAimingCoors), this, AimingTargetCoors);
}

 
Top