1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

GMS 2 How would I make a POV controlled by mouse?

Discussion in 'Programming' started by Alexthom, Dec 4, 2019.

  1. Alexthom

    Alexthom Member

    Joined:
    Dec 3, 2019
    Posts:
    9
    I want to have something where either it just moves to the next wall of a room when the mouse touches left or right of the screen, or make a thing where it just moves when you move the mouse like a POV game. How would I do this?
    Thanks!
     
  2. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,117
    Many different ways. You probably want to start by watching some tutorials on GMS 2 camera in general. I'd start with this: GMS2 Cameras: As Simple as Possible.

    Here are a couple options:
    • set the camera to follow an object and give the object code to do what you want
    • define certain positions in a room and have the camera move between positions when a key or button is pressed
    • set the camera to follow the mouse directly
     
    Alexthom and Cofefe like this.
  3. Cofefe

    Cofefe Member

    Joined:
    Nov 29, 2019
    Posts:
    19
    So in GMS2, what you can do is create an object, you can call it obj_view or whatever you want, and you place it in the room. Then in the room editor, in the properties tab under 'viewports and cameras', enable viewports. Then simply choose a viewport, they are labelled 0-7, set it as visible, and then choose obj_view for 'object following'.

    Then all you need to do is program obj_view to move the way you want it to and the view will follow it. If you wanted it to move to the left or right of the screen based on where you clicked you could do something like this in the mouse click event:
    Code:
    if(x < mouse_x) x = //wherever the right side of yours screen is
    else x = //wherever the left side of your screen is
    And for a very ugly and basic mouse following code, you could place this in the step event:
    Code:
    x += sign(mouse_x - x);
    y += sign(mouse_y - y);
    You can tweak that a little bit to make it less ugly as well as faster and more responsive if you want. Like I said very ugly.
     
    Alexthom likes this.
  4. Alexthom

    Alexthom Member

    Joined:
    Dec 3, 2019
    Posts:
    9
    So for now I was just trying to use keys to make it work...and I tried it before adding textures to all the rooms and it worked..but after adding the objects to make the rooms look good it just gives a black screen...unless I press x to look at the back of the room.
    https://imgur.com/a/iVQ1Sxo
     
  5. Cofefe

    Cofefe Member

    Joined:
    Nov 29, 2019
    Posts:
    19
    So you're saying that adding objects to the room makes the screen go black? Unless you are looking at the back of the room...?

    I'm not really sure what you mean by back of the room, lol. May we see some of your code? That might shed some light on the situation.
     
  6. Alexthom

    Alexthom Member

    Joined:
    Dec 3, 2019
    Posts:
    9
    The imgur link had the code in the video
     
  7. Alexthom

    Alexthom Member

    Joined:
    Dec 3, 2019
    Posts:
    9
    And I made it so that when you would press the w a x d keys, you’d look at all four walls, and s looked down. Each wall is just black except for the back wall, or the x key.
    (W-front,A-left,X-back,D-right,S-down)
     
  8. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,117
    You should review this post. It would help you get better answers to your questions: Posting code on the Programming Forum: Do's and Dont's.

    From watching the video, which is a violation of the forum rules, it looks like all of your 'walls' are different room. This is fine, but it means you won't need to do anything with a camera, at least not inherently. And you cannot 'slide' from room to room. Room transitions are instant.

    If you wanted a 'slide' effect e.g. Myst combined with fully separate rooms, you would need to take a screenshot (likely by using a surface), switch rooms, place the screenshot next to the room, then slide the camera from the screenshot to the room. That is only a very high level overview of the steps you would need.

    I might take a brief step back and review some of the basics of how the GMS 2 IDE works. That would help with asking questions on the forum. Something like this is pretty short but covers the basics fairly well: https://www.youtube.com/playlist?list=PLhIbBGhnxj5I8HuwoNhjgjDC8OQIf8D3Z.
     
    Cofefe likes this.

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