I am working on a project based on the 3rd Person template. I have read several posts here from people asking questions about their player controller they wrote and I was wondering: What’s the benefit of making your own instead of using the one that comes with the template?
I altered the movement system for the character by changing things in the project settings and my character BP without ever having the need to make a player controller.
So what good is is your own player controller? When should you make one and when is the default one good enough?
Imagine you were writing something like Skyrim. The player character is actually quite similar to some of the NPCs in its capabilities. The player can attack with an axe and so can certain NPCs, and so on. I think the idea is that you can write a Character which implements movement, attacks with various weapons, and so on. You can then implement an AIController that drives the NPC version, and a PlayerController that allows the player to control their Character using the keyboard or controller.
If you’re writing a game where the player is very different from the NPCs, there’s probably not much to be gained by splitting it in this way. You can put functionality in your PlayerController or your Character depending on your preference, and it doesn’t matter very much.
I still dont understand, I thought the controller is made to handle input like moving and firing and thus it had to be different for a character that is controlled by the player or one that recieves input from software like the AI system.
I also dont understand why there seem to be two differnt interfaces to a character’s 3D situation. You can access the controller to move the character and get the controllers 3 D position and then you can use stuff like GetActorPosition on the actor.
It’s all very confusing, to decide what code to put where and why. Right now it all goes in the character because I dont have my own controller.
I gonna give you simple and unversal anwser. You only need to create your own classes if you need to alter or extend there behavior of base class, so if you make things work without that, thats ok.
In case of PlayerController, it’s a class which is between player and pawn, as all Controllers (which thereo nly AI one other then that) it’s role is to control possessed pawn, like PeterX said pawn should have switches and buttons that allows to control the pawn and Controller whatever it is Player and AI should able to use them, (So think if Controller as brain for pawn, which you can plug to any of the pawns by possession… or maybe “soul” is better name for that :p), if you make something more comlex then just movement, by convention you should create PlayerController that takesp layer input and calls pawn action.
Yes, AI characters and player characters have different controllers—that’s the point. Suppose you had a game that was a duel between two equal characters: one player, one AI. You could create the same Character for each, but give them different Controllers. One would have a class derived from AIController, the other a class derived from PlayerController. (Different instances of the same Character can have different controllers.)
The Controller decides where it would like the Character to be, and assigns that to its 3D transform. The Character then works towards that, applying constraints on turn rate and so on. For example, the AI might decide that a character should reverse direction, but it should take some time to keep the animation realistic. In this case I think the Controller’s rotation would reverse immediately, and then the Character’s rotation would gradually catch up.