Camera to center on key held and center again on end

Hi,

The function I’m trying to get to work is when the player hits the ‘Q’ key which is mapped to ‘IA_Glance’ the camera looks backwards to simulate the character looking behind them.

At the moment, this is working, except for the issue of the camera being centered, which it doesn’t unless you are centered before pressing the ‘Q’ key.

If the character looks anywhere but center of screen BEFORE pressing ‘Q’ key, then that is the direction the camera will end up looking, when I want it to be centered, not the direction the player was looking in before Q was pressed.

When the character releases the Q key the camera should re-center again anyway because the ‘Q’ key forces a centering of the camera, so no logic should be needed to center again after ‘Q’ key is released.

1 and 2 in the screenshot should be forcing a centering of the camera but it doesn’t, as the -180 forces the direction as I would expect.

3 does not center the camera as I would expect.

NOTE: I’m a month into my game dev journey so I might be asking some eye rolling questions!

eye rolling question

:eyes: Nah, it’s good. But I have a better one.

Is this 3rd person? If so, the camera is, most likely, attached to a springarm (renamed to Camera Boom in the template), right? Shouldn’t you be rotating that instead? It meshes with Control Rotation the Player Controller, Pawns and their cameras mesh with.

Do tell.


Just to ensure there’s no misunderstanding:

  • standard view:

  • glancing back:

How close/far am I from what’s needed here?

1 Like

Thanks for responding! it’s first person, I just started with the third person template, but there is a camera boom/arm thing too with the camera under it, those screenshots are correct just first person camera

Since this is first person, what do you need a springarm for then? How to script it would depend on which components inherits control rotation from a controller.

What’s this offset for?

image

So the head mesh geometry does not get in the way?


it’s first person

Why not then:

Any reason why this is unsuitable? The above produces:

1 Like

Doing those changes works really well! except I can see my characters head even after removing the boom


Ofc, but since this is first person perspective, you do not need a head. Do you?

I broke the camera, not sure why it is doing this now :frowning: I think its when I bound the camera to the head, but I want the head to cast shadows still but I also want it hidden when looking back so I can’t see the inside of his skull

Perhaps have a look at the first person template. There’s a component setup that works really well for this. Perhaps you could replicate it.

but I also want it hidden when looking back so I can’t see the inside of his skull

That is fair, indeed. Offset the camera X, like you did before.

It won’t allow me to do it with a Camera Actor only the Spring Arm which we deleted, anyway to do this with the Camera? couldn’t see an option for it based on my searches, First Person template is good but it doesn’t bind the camera to the head which I want for a more natural movement

This yields all wanted results except for the camera locking when facing behind them
Is it because the Spring Arm itself isn’t configured? if so, how would I do it? I’ve tried a few times with bad results

The camera is a component. And if you’re using a separate camera actor, it still has a component inside.

  1. Camera looks back :white_check_mark:
  2. Camera doesn’t clip through head :white_check_mark:
  3. Camera rotation locks :white_check_mark:
  4. Camera centers when looking back :x: (ideally it centers again when looking back)

Current version - it’s only looking 180 the other way from the current direction the player is looking before they hit the IA_Glance button, so there needs to be something that centers the camera before or after that button press.

For me, it center to my screen so am not sure what different , try to force a look forward with the SetControlRotation such that camera face similar to character forward.


1 Like

This was very helpful! :love_letter:

Edited the BP to look like this, so it works :slight_smile:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.