• 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 View Angle With Player

N

Necromedes

Guest
I'm using Game Maker 1.4.

I'm trying to make the room view angle to match the player image angle.
It works in a sense but not in the way that I'm wanting.

I need the view_angle to match the player's image_angle rotation so that they are constantly facing the top of the screen.

As it stands, the view rotates but the player rotates on the screen as well and doesn't remain facing the top iof the screen.

If you need additional info, let me know and thanks in advance.
 
N

Necromedes

Guest
Pretty much. I've searched for information on this and every post I've found keeps pointing out "You don't rotate the room, you rotate the view," which I'm well aware of. I just need to make it SEEM like the room is rotating with the player.
 

woods

Member
right making the entire room and everything in it spin around your player when you change direction would be pretty taxing i imagine ;o)

off the top of my head something like this...
set up dir facing with the player

Code:
// create event --> create
   /// initialize variables
   
   dir = 0; // variable for direction, must be between 0-3... 0-right, 1-down, 2-left, 3-up
   key_right = ord("D"); // Key to move right. D is ord("D") vk_right is arrow
   key_down = ord("S"); // Key to move down. S is ord("S") vk_down is arrow
   key_left = ord("A"); // Key to move left. A is ord("A") vk_left is arrow
   key_up = ord("W"); // Key to move up. W is ord("W") vk_up is arrow


// step event
   /// movement
   
   if keyboard_check(key_right)
       {
       dir = 0;
       //all your movement code
       }
else
   if keyboard_check(key_down)
       {
       dir = 1;
       //all your movement code
       }
else
   if keyboard_check(key_left)
       {
       dir = 2;
       //all your movement code
       }
else
   if keyboard_check(key_up)
       {
       dir = 3;
       //all your movement code
       }
and rotate the view around the player
camera controller object step event
Code:
view_angle[0] = obj_player.dir
 
N

Necromedes

Guest
Looking at your code, I'm not sure that's what I'm looking for. I am assuming that that code would simply snap the view to one of the 4 degrees, which isn't what I'm wanting.

I'll ad-lib what I'm looking for, instead of using strictly code syntax.

When I press A and D, it turns the player left and right by set degree's, such as 0.2 increments.
When turning left and right, I want to view on screen to rotate with the player but in such a way that the screen stays locked to the direction that they're face.
Basically, imagine sticking a camera on the back of a plane. When the plane turns left, the view of the camera turns with it, etc...

I hope that clarifies things.
 

woods

Member
above was quick copy paste of an older project ive been working with.. the movement bit at least.
you can move your player however you need to to make your game work.. by setting the direction variable and using that with the view_angle to get your room to spin


something more like this then ;o)

if keyboard_check(ord("A")) //left
{
direction +=2;
image_angle = direction;
}
 

Sabnock

Member
cam_angle -= 1;
camera_set_view_angle(cam_angle);

player_angle += 1;
image_angle = player_angle;

extrapolate to suit your code. just a guess mind. never done anything like that in my projects :)
 
view_angle = -image_angle + 90;

So, in this example, the "front" of the player is in the +x direction. If that is not the case for your player, you will likely need to change the constant 90, (to 0 if the player's "front" is in the -y direction).

view_xview = x + dcos(image_angle)*view_offset_x + dsin(image_angle)*view_offset_y - view_wview/2;
view_yview = y - dsin(image_angle)*view_offset_x + dcos(image_angle)*view_offset_y - view_hview/2;

If you want the view offset from your player, for example, to keep your player toward the bottom of the screen, then you can use the above. view_offset_x and view_offset_y are relative to the player, so (assuming player's "front" is in the +x direction) +view_offset_x is in the player's forward direction, and +view_offset_y is toward the player's right direction. If either offset is zero, then terms involving that offset can be eliminated.
 
N

Necromedes

Guest
I decided to simply give the player the option to rotate the room using a key press. This thread can be closed.

Thank you everyone for your advice!
 
Top