Let me start by saying that I’m completely new to game development. I would like to make a top-down 2D game in which there is a “chasing” mechanic. As in: you, the player, are able to chase other characters around the game world.
It seems like GameplayKit would be a good fit for this because it features an agent/goal/behavior system and one of the included behaviors is a goal to “flee” from another agent. I spent a long time looking at the AgentsCatalog sample code that Apple provided and attempted to translate the FleeScene into Swift. This resulted in the following:
The little orange dot follows your touch and the big blue dots flee from the orange dot. At first they just fled right off the screen, so I set up a SpriteKit edge loop to contain them.
Herein lies the problem: All of the dots “stick” to the edge loop instead of bouncing off of it, regardless of how fast they’re moving. They also fail to bounce off of each other. They’ll push each other around a bit, but there’s no bouncing. I have a feeling this has to do with the mismatch between SpriteKit’s physics system and GameplayKit’s agent system, but I don’t know how to fix it.
In the delegate method “agentWillUpdate,” I update the agent’s position to match the sprite’s position. In “agentDidUpdate,” I do the opposite. That’s…probably not right? I have no idea. It’s probably worth noting that I’m not using the Entity-Component system…I just have SKSpriteNodes that own GKAgent2Ds.
Anyway, somebody needs to write a tutorial re: GameplayKit and physics. Please and thank you!