Where do I start with RTS camera?


This is my first post. I have looked everywhere on the web and through the examples; however, I can’t seem to find specific information for getting started. I’ve been poking around for about a week with ue4. The camera and minimap code from the tower defense sample game are pretty much what I want. The problem is that I don’t know which pieces I actually need

Thanks for the help!

The more I dig the less I understand! Well, that’s not entirely true, but my big problem with the engine is that I like to take things little by little. I’d like to get the camera done before I move onto things like the minimap, the structures, the units, etc. I just would love to see a simple example of how to get the camera created. I don’t care about all the other code for all the other systems yet. They will just confuse me… Any tips?

One more comment, I realize there are tons of examples on doing this with blueprint, but I don’t want to use blueprint for this.

The strategy game example has three key classes when it comes to the camera.

First there’s AStrategySpectatorPawn, which inherits from ASpectatorPawn. This is a Pawn type without a Mesh, it’s more of a theoretical pawn in that sense.

Second there’s UStrategyCameraComponent. The AStrategySpectatorPawn has one of these components and it’s the camera you’re looking through.

Third there’s the AStrategyPlayerController. This is a type of PlayerController which will Possess an AStrategySpectatorPawn. From the pawn it gets the CameraComponent and moves it around.

Have a look at these three classes to start with. You can also look at these methods:

void AStrategyPlayerController::ProcessPlayerInput(const float DeltaTime, const bool bGamePaused)
void AStrategyPlayerController::OnTapPressed(const FVector2D& ScreenPosition, float DownTime)
void AStrategyPlayerController::OnHoldPressed(const FVector2D& ScreenPosition, float DownTime)
void AStrategyPlayerController::OnHoldReleased(const FVector2D& ScreenPosition, float DownTime)
void AStrategyPlayerController::OnPinchStarted(const FVector2D& AnchorPosition1, const FVector2D& AnchorPosition2, float DownTime)

void UStrategyCameraComponent::UpdateCameraMovement( const APlayerController* InPlayerController )

And of course the Pawn and PlayerController class to use is specified in the AStrategyGameMode class.

Thank You, I’ve been trying to dissect that code on my own, this should definitely help.

It seems I don’t actually get the mouse trapped at all, unlike the Strategy game. I’m not getting any keyboard focus either. I’ve stepped through my code and it’s hitting all the right spots. Except I never get any key or mouse events/actions. One interesting thing is that the PlayerController is not returning the SpectatorPawn at all. I can’t find any place where that is set. Who sets the Pawn onto the player? :confused:

Follow up question… So, I ported over a bunch of code. I think I’m understanding the bits I’ve grabbed. It turned out that the above code references other code and so I ended up grabbing a bunch other pieces. I’ll need those pieces eventually anyway.

For reference I ended up needing the Interfaces (InputInterface, SelectionInterface, TeamInterface), Pawns (As above + the Movement one), Player (Input and PlayerController as above), GameMode, GameState, Types, Helpers…

This all compiles now; however, once in the editor (I’m using Starter Content) I don’t know how to make the editor use my game code. I’ve tried clicking World Settings and selecting my Game mode which shows me the Pawn, Controller and State classes correctly. When I press play the camera just sits there. (Perhaps that means it is working and the error is in the code… back to digging.

In terms of the original question. This definitely answers the question. I got a little carried away grabbing more code that was not relevant. The camera works perfectly with the spectator pawn. I was just having trouble with the mouse movement code but that was a separate issue.