Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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!

Product Version: Not Selected
more ▼

asked Aug 03 '14 at 10:03 PM in C++ Programming

avatar image

6 2 2 5

avatar image Meneleus Aug 04 '14 at 09:40 PM

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?

avatar image Meneleus Aug 04 '14 at 09:40 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Aug 04 '14 at 10:11 PM

avatar image

1.2k 27 22 211

avatar image Meneleus Aug 05 '14 at 12:24 AM

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

avatar image Meneleus Aug 05 '14 at 02:13 AM

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.

avatar image Meneleus Aug 05 '14 at 02:47 AM

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? :/

avatar image Meneleus Aug 09 '14 at 05:38 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question