I quickly banged together a camera system and spawned in a 2nd player. Works ok. Well and good enough for now, though obviously it could be smarter about how much of each character needs to remain on screen in the vertical.
It’s very rough, but I just needed something workable to get started. The camera actor gets the horizontal distance between characters and does a little math to pull the camera back far enough so each player is in view. There’s probably some fancy equations that take into account FOV, character velocity and all sorts of other factors, but math is hard and so this will do for now. There is a bit of a buffer to keep them in frame at the outer extreme, and a simple collider system is in place to keep the players from getting too far apart. There’s also a limit on how far the camera will tighten up on the characters when close together. This is a number I have tweaked about 9000 times already. I would like nice, big closeups, but at some point the low res voxel style gets difficult to read when too large on screen.
I had not upgraded UE4 versions for some time, so this project started in 4.16. When I updated to 4.19 earlier in the week, stuff broke. It happened to look like this:
If you know which axis UE4 considers “forward” (hint: it’s +X, ) it’s fairly obvious what was going on here, fortunately. The issue was that once I upgraded to 4.19, the camera was spawning before the fighters, so it didn’t know what to look at. As a result the camera was coming in at 0,0,0, looking forward down the X Axis. For some reason, in the earlier 4.16 build of the engine, the camera spawned in after the pawns in a 100% consistent manner, and all was good in the world, so I did not bother dummy proofing it. No idea why an engine update would have cause this, but going to 4.19 exposed a spot of sloppy
coding blueprinting on my part. BUSTED.
PROTIP: There is no guarantee in what order anything in a level is going to spawn in. Account for this.
The fix was pretty simple. I was already spawning my players in via the Game Mode in a specific order. I just removed the camera actor from the level and spawned it in on demand via the Game Mode after the players were in the scene.
Spawn order is a thing that sometimes bites newish UE4 developers. I almost wonder if the engine might benefit from some sort of spawn list that says: “Yo: spawn this, then this, then this, then I don’t really care about the rest; bring it whenever.”
Loads of successful games have been built, shipped, and sold without this functionality, so perhaps this is something of a non issue. IDK.
You may notice that the two characters not only feature different color schemes, but different costumes than previously shown. More on this in another post. (Admittedly, I am somewhat proud of this feature.)
Subscribe for best life.