playMaker

Author Topic: How Can I Keep The Players Within the Camera View Bounds  (Read 4258 times)

G-Kaiser

  • Playmaker Newbie
  • *
  • Posts: 34
How Can I Keep The Players Within the Camera View Bounds
« on: July 16, 2014, 12:58:39 AM »
Hello,

I am working on a 2d Fighting game. I have my camera set up to where it follows the players and zooms in and out. I cannot figure out how to get the players to stay within the bounds of the camera view. Because the camera zooms and moves it seems to be hard to do with the Float Clamp. I cannot set a variable for the left and right side of the camera. Is this even possible with any of the Playmaker actions? I would like know how can make it so that the players do not leave the camera's view when moving around on screen? Any help would be appreciated. Thanks.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4002
  • Official Playmaker Support
    • LinkedIn
Re: How Can I Keep The Players Within the Camera View Bounds
« Reply #1 on: July 16, 2014, 01:32:57 AM »
If it's just 2 players you can start by keeping the camera centered on the mid point between players. Now you have to move the camera forward/backwards to keep them in view. You could measure the distance between players and use that to set the desired distance of the camera. This could be a simple multiplier, or you could create a relationship using Sample Curve - basically defining the desired camera distance for any given separation of the players. This makes it easy to enforce min/max distance, easing in/out etc.

Once you've calculated the desired position of the camera, you should smoothly move the camera towards that position every frame, instead of just setting the position. This should give you a looser more natural camera.

Does that make sense? Drawing a top down diagram will help visualize the setup...

G-Kaiser

  • Playmaker Newbie
  • *
  • Posts: 34
Re: How Can I Keep The Players Within the Camera View Bounds
« Reply #2 on: July 16, 2014, 04:09:21 AM »
Is there any way to get more detailed information on how to use the Sample Curve action? I already have my camera set up to pan and zoom but your explanation seems like a better option. The camera set up that I currently have moves with the players by detecting a key press. The only problem is that I cannot get the camera to keep the players within the camera view if they get too far apart. The camera edges should work as a wall to keep the players from going off screen. Will your advice work for that as well?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How Can I Keep The Players Within the Camera View Bounds
« Reply #3 on: July 16, 2014, 09:21:50 AM »
Hi,

 Typically then, make real walls attached to your camera, that's how it's done in the M2H samples ported to PlayMaker.

https://hutonggames.fogbugz.com/default.asp?W890

If you have colliders on each side of your camera, then your player won't be able to move out of view. Also, this example also show a way to automatically follow the player as it moves up and up, this is typically what you want, applied to all directions.

Bye,

 Jean

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: How Can I Keep The Players Within the Camera View Bounds
« Reply #4 on: July 16, 2014, 09:29:46 AM »
Check this thread out for some related discussions:
http://hutonggames.com/playmakerforum/index.php?topic=6843

Doesn't look like we got to the wall limits, but colliders at the extents of the camera are probably the solution.
« Last Edit: July 16, 2014, 09:33:36 AM by Lane »
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D