# Camera Z angle

## Recommended Posts

Hello,

I was wondering how to get the angle that the camera is pointing to, but im not too sure how to work it out- any help would be appreciated

##### Share on other sites

I think the angle is constant but the height adjusts from vehicle to vehicle. I'm also pretty sure it's hardcoded, as the dff dummy placements have no apparent effect and there's nothing in the scm files.

##### Share on other sites

It hasnt got much to do with cars, its about getting the direction the camera is facing regardless of whether an actor is on foot, in a car etc.

I think it could be done by getting the camera position and target point, then doing some sort of equation to convert it to a direction (0.0 north 180.0 south etc)

if i work it out ill post it on here so others can use it, but dont count on that lol

##### Share on other sites

`068D: get_camera_position_to 0@ 1@ 2@068E: get_camera_target_point_to 2@ 3@ 4@0063: 0@ -= 2@0063: 1@ -= 3@0604: get_Z_angle_from_vector 0@ 1@ store_to 4@`

Thanks, Deji

##### Share on other sites

Hello again- i have found a use for the X angle as well, but getting it is slightly different to getting the Z angle, how exactly do i work it out? I feel i may be getting annoying here but mathematics is not my forte

Any help would be appreciated

##### Share on other sites

By "X Angle", what exactly do you mean?

Y Angle = Up/Down

Z Angle = Left/Right

If you do mean the Up/Down angle (which is hugely more complex than getting the Z Angle), you need Atan. Ryosuke made a function to calculate Atan here. Call the address of ATAN2_X86 like done in the code and you should have the right angular value.

##### Share on other sites

Thank you Deji- Yeah i was talking about the pitch/roll/yaw angles. I will give atan a go and see what it involves

##### Share on other sites

OK it almost works, part of the script im making allows the player to turn in midair, and the results i get work perfectly if the actor is facing south, but inverts 180 degrees when facing north. I believe its the inputs i have been using- what should i use, or am i missing a step?

##### Share on other sites

Use some sine/cosine multiplers to set it properly instead. However, usage of them depends how do you want to use calculated offsets, so I can't give you whole code.

##### Share on other sites

Ok, i am not sure what to sine and cosine, and what the offsets should be- this is different to anything i have done before to do with angles, but im willing to learn

Just out of interest, does anyone here use the IRC channel?

##### Share on other sites

• 2 weeks later...

Ok, im guessing nobody knows how to solve this, but i havent given up with it because i think the feature will make a great addition to the script and i really dont want to throw it out- i dont want the code to copy and paste in, i would just like it explained so i can do it myself and learn from it.

##### Share on other sites

Ok, im guessing nobody knows how to solve this, but i havent given up with it because i think the feature will make a great addition to the script and i really dont want to throw it out- i dont want the code to copy and paste in, i would just like it explained so i can do it myself and learn from it.

those calculations are difficult to explain and can differ depending to your plan

so post your script and explain your plan, then we can help

##### Share on other sites

Thanks for the help, ZAZ- the code is a subroutine that changes the players facing while in midair, i think that where i multiplied by -1 is a clue because it lets the code work 180 degrees in the other direction (the player flips over if he goes past east or west)

I also tried it both using Atan2 and 0604 and they appear to have the same effect

`:A068D: get_camera_position_to 0@ 1@ 2@068E: get_camera_target_point_to 2@ 3@ 4@0063: 0@ -= 2@0063: 1@ -= 3@0604: get_Z_angle_from_vector 0@ 1@ store_to 11@11@ -= 180.0 0173: set_actor \$PLAYER_ACTOR Z_angle_to 11@068D: get_camera_position_to 0@ 1@ 2@068E: get_camera_target_point_to 3@ 4@ 5@0063: 1@ -= 4@0063: 2@ -= 5@//gosub @ATAN2_FPU0604: get_Z_angle_from_vector 1@ 2@ store_to 22@22@ *= -1.022@ -= 90.0083E: set_actor \$PLAYER_ACTOR rotation 22@ 0.0 11@ while_in_air return`

##### Share on other sites

That opcode returns the atan2 result between y and x, but the value is an absolute degrees.

## Create an account

Register a new account

×