How do I make so I can "push" the camera when I get the mouse close to the screen edge

Hello, I want to make the camera push around when the mouse moves close to the screen’s edge. Something like this

but without having to hold down click, if possible moving it smoothly. I have tried some youtube tutorials but I can’t get UE to manually detect the mouse and get the mouse delta to move the camera accordingly. Help would be appreciated

Hi there,

Think you can

Controller->GetHitResultsUnderCursorByChannel->BreakResults->ImpactLocation

TargetRotation = FindLookAtRotation (PlayerCameraPositon, ImpactLocation)

OnTick->SetCameraRotation – > RotationInterpTo (PlayerCameraRotation, TargetRotation, Speed, Tick )

If you use controller rotation SetController rotation that should work too but if you just want on the edges think you have to calculate mouse position in screen first. You can access that too and upon reaching edges( if X< Number || X>Number) same for y-axis too do tick operation for rotation.

Let me know if it helps

1 Like

Hi there, thank you for your reply, but, I cannot seem to locate the following nodes:

PlayerCameraPosition, SetCameraRotation, PlayerCameraRotation

I couldn’t also find some nodes by the name you gave me, but I saw similar names and figured they should work, correct me if I am mistaken.

ImpactLocation → Hit Result Location

Also, I don’t quite get the last part where you say:

Could you explain it again but in dumber terms? I am quite new to the engine and I’m still figuring it out.

By the way, it would help me a lot if you could provide some pictures of a blueprint that does what you described. Thanks again

Hey no worries,

Since you want to control camera, the settings of how its setup really effects our logic. Sometimes we use options in pawn/camera/springarm → Use Controller Yaw/Pitch/Roll with UseControllerDesiredRotation. for different view models.

Like in 3rd person camera should act differently depending on gameplay and gameplay ux. I press forward, then back → Should my character pawn turn to controller side or not?

In camera can be also options like

depending on how you setup our logic can be different. However this is for a third person template for 5.6.

This simply will follow my mouse rotation.

However we have to control camera to world interaction right? Like when this function should fire? If fired everytick it will always try turn on one side, is this something we want? etc. etc.

So I will just do things according to mouse pos, calculate a delta from center, check if its above some threshold and manipulate Controller Rot, which would work exactly like your video.

Results


If you don’t use controller rotation , you can simply delta rotate camera/spring arm relative to controller or something static in camera like below.

Since my character facing doesn’t change in capsule this time, I can just delta rotate spring arm. This is something more likelly you show since in the edges your camera stops as mouse delta, however both approaches are ok depending on what you do.

Results

Let us know.

Hi, is there anyway to make a “speed gradient” so that the further away from the center the mouse is, the faster the turning speed is?

By the way, this is exactly what I wanted to achieve this is just one extra detail that would just make it perfect.

In the first & seconds videos its already like that.
In the third video if you are referring to; you can do with multiple ways.

A correct way is to create a curve and get its values. Especially if you want complete control over your numbers and movements. Here is a nice tutorial in depth explaining base fundamentals of working with curves.

A simpler more direct way is keep factor rotation very small and get a double power exponent to values making it n to the power scaling to infinity.


Hi, after much adjusting I modified your code a bit to add the curves and stuff, which came up like this

which is exactly what I wanted.

this is the gameplay

Glad that it worked, let me know if you would need further assistance.

Good luck :four_leaf_clover:

Hi, I just built the application and move the mouse cursor to the edge, the camera starts turning backwards at some point, just like this

Well think we should first understand how you setup things and how your character moves.

There is couple of concepts to begin with.

You camera movement and rotation doesn’t means your character is turning.-> That is controlled by your settings. Usually with controller rotation. Character Controls Camera is something that influences each other.

On the example you did think you are using . UseDesiredControllerRotation on your movement and since you take mouse right. It turns camera->thus it turns a bit controller with and endlless cyclle as expected.

If you explain how your character is expected to turn maybe I can help more, cause if we limit as you said you simply cannot turn with camera. If you have tank controls etc as movement thats another story ofcourse.

However if you want limit while not moving, and have rotations while moving you can do something like this or use controller rotation on movement else not would also work.

Hi, my bad, I hadn’t fully explained how I wanted the camera to move. Sorry.

I know how to clamp the camera rotation, and I have done so for the Y axis, but I want the player to be able to turn around in endless circles, so the camera moves as it should, but the thing is that when I built the application, turning the mouse all the way to the right results in the character turning left, but turning the mouse half way right results in the character turning with the desired turn speed to the right. I thought there might be something wrong with the float curves, but I do not see anything wrong with them.

The thing is that the issue is not present wile running the game from the engine, It only appears when I package the application and run it.

ok understood then its good the problem simply : You cannot see what you built in editor.

No worries :slight_smile: can happen with many things, its good that you compile for test.

Generally couple of things can go off.

    • Things you added did not make to final build. Sometimes assets if not explicitly crafted (not engine asset) and referenced would not make into compiled build.
  1. Calculations are hijacked somewhere or some settings overrides things.

What I think your curve is not making into the builld possibly. What you can do, you can make sure its referenced in some content folder and in your BP.

2nd option is to go ProjectSettings->Packaging->Advanced->Additional Cook. There should be some folders that you can add over there so its cooked and makes into final builld.

Before that if you want you can go into packaging logs and simply search your curve name over there to see if it already throw some errors or warnings.

I just discovered that it only happens of full screen, pay attention to the mouse, see how it starts turning the opposite direction once it reaches the edge on full screen?

Not sure tbh,

It can be coming from your curve values maybe if you set infinite loops.

It can be a desync between viewport and mouse position. Possibly viewport size updated but mouse position can be still old dimension causing problem.

Try checking your curves cover over a value range -3000 +3000, try setting resolution r.SetRes 1920x1080w or r.SetRes 1920x1080f to see its solving any problems.

Hi, how do I force the full screen resolution to be 1280x720

I discovered that only the code start to behave weirdly when the resolution is above 1280x720, I searched how to do it in google but it only shows how to make like an options menu, but I don’t want an options menu I just want that to be the one and only resolution

well apparently it has something to do with the value being multiplied here

for some reason if that value excedes 18.8 the camera will start turning in the opposite direction once the mouse has exceded the edge of the screen. I don’t exactly know why, I just change the graph and went with it

Edit:

The reason why the camera starts turning in the opposite direction is because when multiplying the decomposed vector by a number, if the results exceeds 360 the engine automatically wraps around the number to zero so it starts turning in the opposite direction

1 Like