• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Rotating camera with player

B

boowee

Guest
Hi,

Fairly new to GM and coding and I am trying to rotate the camera based on which direction the player is facing, but I must be thinking about this the wrong way and it might be a stupid question.

To do this I am trying to define the up vector for the camera based on the players image_angle.

This is the code I have now, which is basically not doing anything :) but the idea was to create a vector between the player and a point in its facing direction:

----------------------------------------------------------------------------

xUp = oPlayer.x - lengthdir_x(100, oPlayer.image_angle)
yUp = oPlayer.y - lengthdir_y(100, oPlayer.image_angle)

var vm = matrix_build_lookat(x,y,-10,x, y,0,xUp,yUp,0);

camera_set_view_mat(camera,vm)

----------------------------------------------------------------------------

This should probably be done in a completely different way but I would appreciate any pointers or help on this.

Thanks!
 
B

boowee

Guest
Maybe this was poorly described. But without getting into my assumed solutions, what I want to do is the follow:

As the camera follows the player (movement) which is already in place and working, the camera should also rotate to always face the same direction as the player. By this I mean the "up" vector of the camera should be equal to the player image_angle and/or current direction.

Anyone?
 

andev

Member
This is the code I have now, which is basically not doing anything
In GM1.4, for the views to do anything, you have to check "Enable the use of views" in the room settings (views tab), and also enable "visible when room starts". You might have to do something similar.
 
B

boowee

Guest
Hi,

thanks for your response, but this is checked and not the issue. I actually get this to work when I am using an enemies x and y to get the xUp and yUp vectors so I am still very confused why the same thing would not work using lengthdir to get x and y in front of the players facing direction
 
Top