playMaker

Author Topic: Camera Follow multiple target - Top view  (Read 4107 times)

Cedrikk

  • Playmaker Newbie
  • *
  • Posts: 1
Camera Follow multiple target - Top view
« on: March 29, 2014, 05:47:10 PM »
Hello,

I'm actually making a little top view video game, a very basic one.
I wondering if it's possible to have a camera following 2 players in same time?

By this I mean the camera should zoom in or zoom out regarding at which distance the two players are. It's very common in this kind of game.

But I don't know how to do it with playmaker? Do you have any idea on how to do it?
Thanks in advance.

Breadman

  • Full Member
  • ***
  • Posts: 185
  • Derp
Re: Camera Follow multiple target - Top view
« Reply #1 on: March 31, 2014, 01:49:50 AM »
I've never done this before, so I don't know the exact actions you'd use, but in terms of logic I'd go about this way:

1. Calculate the distance between the two players every frame, output to some variable. I think you would use a raycast for this.

2. Use that variable to control the zoom level of the camera (and position if needed) - you may need some math actions to get it working right. You'll need to experiment with numbers to get the zoom level just right. Maybe if the players are 15 units apart, you find that the camera looks best zoomed 150 units away. This would mean you take the variable, multiply it by 10 every fame, store it in a new variable, and then set the zoom distance of the camera to the new multiplied variable every frame.

3. If the camera moves horizontally as well, you would set its position to the center of the raycast line drawn between the two two players ever frame.

Sorry I don't know exactly what to do, but hopefully that points you in the right direction! :D

Sly

  • Full Member
  • ***
  • Posts: 123
Re: Camera Follow multiple target - Top view
« Reply #2 on: March 31, 2014, 10:33:56 AM »
I was interest by this too.

Breadman, it's not a stupid idea! And using raycasting can be a good idea too.
I don't want to make Cedrikk problem more complicate, but I wonder if this method can work with more than 2 players, like 3 or 4.

Anyway interesting!

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Camera Follow multiple target - Top view
« Reply #3 on: March 31, 2014, 11:16:12 AM »
Give this a try. Move the spheres around.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Sly

  • Full Member
  • ***
  • Posts: 123
Re: Camera Follow multiple target - Top view
« Reply #4 on: April 01, 2014, 10:27:37 AM »
Cool! It's working great! Thanks for your help Lane!

I don't want to abuse of your kindness but do you know how to prevent players to leave the camera? I mean I want to prevent the player to be out of the camera view. Usually in game of this kind, players can leave the camera field of view because it's blocking the player.

Do you know how to do that?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Camera Follow multiple target - Top view
« Reply #5 on: April 01, 2014, 10:31:27 AM »
I knew that was coming! ;)

You can do it a few ways, but I think the easiest is creating a few colliders at the outskirts of the camera frustrum that only collide with the player tag. You can set that up in the PhysicsManager Layer Collision Matrix.

More tweaking to the system would certainly be needed to sort out the kinks, but its a good start.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

Sly

  • Full Member
  • ***
  • Posts: 123
Re: Camera Follow multiple target - Top view
« Reply #6 on: April 01, 2014, 11:24:58 AM »
Cool, thanks for the good idea.
And like I said I don't want to abuse of your help.
You already gave a great help, thanks a lot for what you did, it's really appreciate!

Sly

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Camera Follow multiple target - Top view
« Reply #7 on: April 01, 2014, 11:28:40 AM »
It's no problem, don't hesitate to ask for help here! :)
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D