Constraining movement to the camera

MonjiOMonjiO Member Posts: 20
edited November -1 in Working with GS (Mac)
Hello all, MonjiO again with another (hopefully easily solved) problem: how can I constrain the payer's movement to the camera in a side-scrolling game?

Right now (working off of the shmup template) I have the Camera Follows Me Behavior creating the scrolling level effect. I've also made an actor using the How Do I Create A Wall tutorial with three bhaviors: Collision with the player and Constrain Attributes set to the game.DisplaySize settings. I have also made top and bottom boundaries that collide with the player.

The effects of all of these are that the player is constrained in his top, bottom, and left movement but can still move past the display if moving right. Is there some piece of logic I'm missing or a behavior that could be better used than the setup I have now? The goal, of course, is to make it so that the player can't move out of the bounds of the camera.

Comments

  • TobyToby Member Posts: 478
    Use the control camera behaviour. Apply the control camera to the player actor and this will do the trick. Probably would be helpful to you if you had a look at all the defined behaviours and read the description for each so you get an idea of what's possible and funtionality available. Might want to make sure your stage or level size is bigger than the default 480 x 320 so the player has somewhere to scroll to and switch of wrapping!
  • MonjiOMonjiO Member Posts: 20
    The Control Camera action is needed on another actor due to how I've got my enemy spawns working (in order to get them to spawn outside the display area, I need an actor that isn't the player controlling the camera).

    I have tried the Control Camera action on the player, and while it does strictly speaking accomplish the goal it also leads to a whole lot of terrible-looking scrolling that would, I'm assuming, require more work to fix than if I were able to create a moving wall around the player.

    Correct me if I'm wrong, but if I've got an object that has the dimensions of the display and the player collides with it, shouldn't that be true of all 4 sides of the display? Basically I don't understand why the right-side collision isn't working.
  • TobyToby Member Posts: 478
    Bit fuzzy on what you are trying to achieve? Maybe some screenshots and a detailed description might help?
  • MonjiOMonjiO Member Posts: 20
    I'm hesitant to post screenshots (because it's not that amazing looking, yet), but I can give a detailed description of what I'm looking for:

    I want the player to be unable to move past the display area, as in the size of the viewing screen or dimensions of the camera (X and Y values). I have another object controlling the camera to make the level scroll, and I DO NOT want to give the player the Control Camera behavior. The level, in this case, has a greater X amount than the game's display size.

    My resolution has been in two stages so far. The first was to create actors at the top and bottom of the level, with the Collide behavior. These actors prevent the player's Y value from exceeding the display area.

    The next step was to limit the player's possible X values. To do this, I made an actor with the behavior Constrain Attribute, setting the actors X and Y values equal to the game's display size. I then gave this actor the Collide behavior with the player.

    The culmination of these actors is that the player cannot move outisde the display on all sides except the right side of the display.
  • CodeMonkeyCodeMonkey Head Chef, Member, PRO Posts: 1,803
    You could create an actor that constrains the values of the camera origin to game attributes(game.CamOriginX and game.CamOriginY). You would need to add the actor to the scene and then edit this instance to be able to access the scene attributes.

    With the camera origin now available as game attributes, you could check the position of your player against that with 4 rules.

    If Attribute self.Position.X is < game.CamOriginX,
    -- Constrain Attribute: self.Position.X to game.CamOriginX

    If Attribute self.Position.X is > game.CamOriginX+480,
    -- Constrain Attribute: self.Position.X to (game.CamOriginX+480)

    If Attribute self.Position.Y is < game.CamOriginY,
    -- Constrain Attribute: self.Position.Y to game.CamOriginY

    If Attribute self.Position.Y is > game.CamOriginY+320,
    -- Constrain Attribute: self.Position.Y to (game.CamOriginY+320)
Sign In or Register to comment.