How do I make a camera tether?

0 favourites
  • 2 posts
From the Asset Store
Simple and easily editable template for a dynamic camera that zooms in and out based on how far apart the players are.
  • Hi, I'm pretty new to Construct 3 and have played around with Scollto camera as well as creating a "ghost" sprite that moves using wasd, acting as a free moving camera. Overall it was simple enough.

    What I really want to make but can't figure out is a camera that is controlled by wasd but can't move a certain distance away from units controlled by the Player.

    Example, The Player controls 3 different units in an RTS fashion and can easily move the camera roughly 4meters away from the units but no further. If the unit goes out of range of the camera, said camera will follow. Creating a field of view of sorts for the player.

    I can't figure this out, is it possible? Or is it easy and I'm just blind?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It's possible, but has the potential to be very very complicated. There are essays and essays about how good camera control is handled in games, and there are a lot of subtle differences between games too, so there's not really a one size fits all type of solution.

    For your described scenario, you'll want to identify the center point between the selected units, and then set bounds for the "camera" object based on that center point. The clamp() expression can be used to keep a value (x and y positions in this case) within those bounds.

    First the center point. Assuming you want a flexible number of units, you'll want two variables (or an invisible helper sprite) to keep track of x and y values. Add all the selected x or y positions together and divide by the number of units selected. How exactly you go about picking the units will be dependant on how your unit selection is set up.

    For the scroll to camera object, every tick set it's x position to clamp(centerpoint.x-range,self.x,centerpoint.x+range) and similar for y, where range is how far you want the camera to be able to move from the center.

    You'll probably eventually want some way to have the camera automatically drift or reset back to the center as well. You'll need to describe under what conditions and how you want that to happen.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)