# GMS 2Rotating camera

B

#### boowee

##### Guest
Hi,

I am new to GM and am currently trying to figure out how to rotate the camera using the new camera system. Basically what I am trying to do is have the camera rotate based on a direction from the player object to another object.

In other words the camera should be following the player in terms of position but rotate based on a direction to another object

My initial idea was to make the view_angle equal to the point direction of the other object, but I am not getting it to work.

Looking at the "new" camera system it seems rotation is based on setting the "up" vector in the lookat matrix?

I hope this make somewhat sense.

#### jo-thijs

##### Member
Hi,

I am new to GM and am currently trying to figure out how to rotate the camera using the new camera system. Basically what I am trying to do is have the camera rotate based on a direction from the player object to another object.

In other words the camera should be following the player in terms of position but rotate based on a direction to another object

My initial idea was to make the view_angle equal to the point direction of the other object, but I am not getting it to work.

Looking at the "new" camera system it seems rotation is based on setting the "up" vector in the lookat matrix?

I hope this make somewhat sense.
Hi!

It does not seem like that is the case.

Using view_get_camera and camera_set_view_angle seems to do the job like view_angle previously used to do.

#### flyingsaucerinvasion

##### Member
if you have two points, A and B, and you want your up vector to point from A to B, then your upvector can just be B - A. You probably don't even need to normalize because the build lookat matrix function i'm pretty sure will normalize for you.

if you want the up vector to point 90 degrees anti-clockwise of the angle from A to B, then the upvector is (B.y - A.y,A.x - B.x, 0). 90 degrees clockwise would be (A.y - B.y,B.x - A.x, 0). I'm assuming you're dealing with 2d, so z component should be zero.

I'd be surprised if GMS2 doesn't have a function that lets you change the up vector by providing an angle as an argument.

Last edited:
B

#### boowee

##### Guest
if you have two points, A and B, and you want your up vector to point from A to B, then your upvector can just be B - A. You probably don't even need to normalize because the build lookat matrix i'm pretty sure will normalize for you.

if you want the up vector to point 90 degrees anti-clockwise of the angle from A to B, then the upvector is (B.y - A.y,A.x - B.x, 0). 90 degrees clockwise would be (A.y - B.y,B.x - A.x, 0). I'm assuming you're dealing with 2d, so z component should be zero.

I'd be surprised if GMS2 doesn't have a function that lets you change the up vector by providing an angle as an argument.
This is great, worked like a charm! Realizing I suck at math the two variants you suggest above makes sure B is always to the right or left hand side of A in the view. Would you be able to help me in how to write it so that B is always straight above A (0 degrees? In other words I want B to be in the direction towards to top side of the view.

Sorry if this came out confusing.

#### flyingsaucerinvasion

##### Member
Yeah, the first thing I wrote, B-A.

(B.x - A.x, B.y - A.y, 0)