1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

How do you make the map rotate instead of the player?

Discussion in 'Programming' started by sloodger, Oct 22, 2017.

  1. sloodger

    sloodger Member

    Joined:
    Oct 22, 2017
    Posts:
    3
    Goooooood afternoon! I'm here trying to make a topdown shooter where rather than the character rotating in endless circles, he stays facing up and the ground beneath him rotates, using 8 directions with his movements. I've been looking all over the place for a good couple hours, any suggestions?
     
  2. Xer0botXer0

    Xer0botXer0 Member

    Joined:
    Jun 29, 2016
    Posts:
    668
    Based on my half assed attempt at understanding how to do this, you should consider the dimensions( x/width/y/height) of your game world within a room, then you want the room to be large enough to simulate rotation of your game world else the corners will get cut.

    And then I'm not sure if this is possible or not but using draw_surface_ext you could draw the application surface and rotate it.
    That's one idea, if that doesn't work then you could create a sprite from the application surface then draw the sprite and rotate that

    But my best guess is using a combination of point_direction and length_dirx/y and vk_left/vk_right to move objects around you like a clock.
     
  3. Roderick

    Roderick Member

    Joined:
    Jun 22, 2016
    Posts:
    577
    Use view_angle.

    If you're using 2.x, I think the command is different, but there should be an analogue.

    Edit: Looks like camera_set_view_angle is the 2.x equivalent.
     
    ParodyKnaveBob and Xer0botXer0 like this.
  4. sloodger

    sloodger Member

    Joined:
    Oct 22, 2017
    Posts:
    3
    my knowledge of this program is slim to none. the only issue I'm having, is that there are objects within the room that I need to move with the room. would the code for the rotation of the room be virtually the same if added to the objects?
     
  5. Xer0botXer0

    Xer0botXer0 Member

    Joined:
    Jun 29, 2016
    Posts:
    668
    Regarding rotating the view, that means the whole game view will rotate the same as rotating your monitor, from what I understand you want the view to rotate around your player so you'd have to counteract it by changing your player objects image_angle in the opposite direction.

    The alternative method with rotating objects around your character would have a higher cpu load. And your background wont rotate with it.
     
  6. sloodger

    sloodger Member

    Joined:
    Oct 22, 2017
    Posts:
    3
    there has to be a way for me to snap the camera angle to the player so I don't have to go Tony Hawk Pro Skater 2 on other objects and animations code for rotation.
     
  7. Wraithious

    Wraithious Member

    Joined:
    Jun 24, 2016
    Posts:
    1,166
    If your other objects don't move just put a check in the step event using
    Code:
    x= view_xview[ i ]+ theXValue;
    y=view_yview[ i ]+ theYValue;
    Or if they do move, use a movement format like
    Code:
    x= view_xview[ i ]+ theXValue;
    theXValue+=hspeed;
    y= view_xview[ i ]+ theyValue;
    theyValue+=vspeed;
    
    To get the non player objects to stay facing the correct image_angle you'd have to use some combination of the view_angle and the hspeed and vspeed variables and their resulting image_angle, not sure what the formula is for that but it shouldn't be too hard to come up with one.

    EDIT:
    I just messed around with this and you don't need to do anything with image_angle of non player objects if they aren't moving but you do if they are, so this is what I came up with inside a non player object
    create event:
    Code:
    x=100;
    y=100;
    trackdir=0;
    theXValue=100;
    theYValue=100;
    step event:
    Code:
    if(hspeed=0 && vspeed=0)
    {x= view_xview[0]+ theXValue;
    y=view_yview[0]+ theYValue;
    }
    if(hspeed !=0 || vspeed !=0)
    {x= view_xview[0]+ theXValue;
    theXValue+=hspeed;
    y= view_xview[0]+ theYValue;
    theYValue+=vspeed;
    image_angle=view_angle-trackdir
    }
    if hspeed<0 && vspeed=0 trackdir=view_angle-180;
    if hspeed>0 && vspeed=0 trackdir=view_angle;
    if hspeed=0 && vspeed<0 trackdir=view_angle-90;
    if hspeed=0 && vspeed>0 trackdir=view_angle-270;
    if hspeed<0 && vspeed<0 trackdir=view_angle-135;
    if hspeed<0 && vspeed>0 trackdir=view_angle-225;
    if hspeed>0 && vspeed<0 trackdir=view_angle-45;
    if hspeed>0 && vspeed>0 trackdir=view_angle-315;
    
    if( !keyboard_check(ord('A')) && !keyboard_check(ord('W')) && !keyboard_check(ord('S')) && !keyboard_check(ord('D'))){hspeed=0;vspeed=0;} 
    if keyboard_check(ord('A')) hspeed=-5;
    if keyboard_check(ord('W')) vspeed=-5;
    if keyboard_check(ord('S')) vspeed=5;
    if keyboard_check(ord('D')) hspeed=5;
    if keyboard_check(vk_left) view_angle+=1;
    if view_angle>359 view_angle=0;
    if keyboard_check(vk_right) view_angle-=1;
    if view_angle<0 view_angle=359;
    
     
    Last edited: Oct 29, 2017

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice