Initial camera direction issue

Hello!

I’m quite new to Unreal, so please excuse me if this question is obvious. I’m using PolygonJelly’s train and track system, and I’m trying to implement a 1st person camera that hovers directly in front of the train. Although the camera is attached to the train, the player should be able to use the mouse to look around. I’ve gotten much of this working beautifully - thankfully, many of these questions have been discussed before, and I did my best to google the answers.

My issue is that, when the level begins, my camera isn’t pointing in the same direction as the train that it’s attached to. It’s peering off to the side. However, everything else works great. The mouse can be used to move the camera around, and the camera position is locked on to the train engine car. It’s just when the level starts, I would like the camera to be facing… well… the same direction as the camera actor that I’ve added to the level.

Here’s a screen capture which shows that I’ve created a CameraActor_Blueprint, and that it’s auto-activated for player1. You can also see that it’s a child of my BP_TrainEngine:

And here’s my blueprint, which does all of the work:

If those images are too small to view, here are links to hosted versions:

So, just to reiterate, when the level starts, here’s where the camera is pointing:

And here’s where the camera should be facing:

Any help would be much appreciated!

looks like your trying to center mouse on begin play which is fine.

your pulling the player controller off the tick which i don’t believe gets the reference until after the begin play.

Maybe add another get controller at begin play instead of feeding off the one on the tick ?

Im not 100% sure but its worth a shot.

Exonfluxx, I totally appreciate your help. It didn’t turn out to be a timing issue, but rather I was approaching it wrong. Here’s what ultimately worked for me:

I do have an additional issue that’s probably unrelated to the one I solved. Once the mouse X position reaches 0, I’m unable to look further to the left. I’m guessing that Rinterp To might be having issues the mouse position becomes negative. I’ll have to research this further, but I wanted to note it in case someone else uses this blueprint.

I know this may be a bit radical… but you might consider revising your whole approach

UE4 has a bunch of simple functions to handle mouse input and rotation… it’s just a few nodes in BP…

if it is me, I’d use as your “player” a Spring Arm Component and Camera, attach it as a child of your train in BP or in level outliner (facing in the direction you like). Use the nodes Add Controller Yaw Input and Controller Pitch Input (if you need pitch, there is also roll) to allow your player to rotate it as the train moves about.

anyway, just a thought…

Hi @aNorthStar,

Thanks for the insights. I like your idea, and I’ve almost succeeded in implementing it, but I ran into some trouble. I did what you recommended and added a player character with a spring arm and camera, like so:

Things got a little tricky, because as a child of my train engine, the camera would move along with the train, but if the train turned, the camera wouldn’t. I realized at that the camera will need to rotate along with the train, plus react to mouse movement. I got the 1st part of this done, as you can see here:

You can see in the blueprint above that I tried to add the Input Axis Turn to the train’s forward vector. This didn’t work. I output the value of Input Axis Turn, and found that when I moved the mouse left or right, the output swung from -1 to 1, which would be fine because I could multiply it. However, the InputAxis Turn output would snap back to 0 when the mouse was no longer in motion, resulting in a very jittery camera. Clearly I’m not approaching it correctly. Any suggestions?

hiya back @clone45 :slight_smile:

As you might guess, I’m trying to figure out a way to achieve your result without any BP programming at all… just the right settings in the right 3 places. There are a few features of UE4 Character actors that might work in your favor.

I think you are on the right track, attaching your empty player character to the train (there are a few different ways of doing this… and the method you use to attach is likely to affect how the train rotation automatically translates to your character’s rotation). I haven’t tried to do exactly what you are doing, but if it is me, I’d take the following initial steps in the following three areas:

a) in the Character Actor base settings

  • under Pawn > Use Control Rotation Pitch / Yaw / Roll

b) in the Spring Arm Component settings

  • under Camera Settings > Use Pawn Control Rotation also Inherit Pitch / Yaw / Roll
  • under Lag > Lag and Rotation Lag settings will smooth your camera movements (it looks lovely)

c) in the Character Component settings

  • under Character Movement (Rotation Settings) > Rotation Rate, Use Desired Controller Rotation and Orient Rotation to Movement

See how this goes… play about with the following settings to understand what they do. If none of the above combinations suits your needs, we can look at two more things:

  • how to best attach the Character to the train (keeping the above settings in mind)
  • or… finally… if it comes to it… add some BP logic to translate the rotation of the train and add the yaw/pitch/roll controller input together… but first try it without any BP programming at all… it will be the smoothest and highest performing.