x

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"

How to smoothly reset camera position without use of "SetControlRotation"

Hi, this is something I have been struggling with for quite some time now. I'm creating a third person game where I would like to have the ability to freely move the camera around the player (ie GTA V) and then with a button press reset the camera to its starting position, blending with (ease) from point A to point B. I have achieved this by following this video tutorial: https://www.youtube.com/watch?v=AOTRu6CxzpE&t=2s

My issue is that this way of resetting the camera position ends in "SetControlRotation". So if I hit the assigned reset button while the player is moving left or right the camera will spin continuously until the player has stopped moving. I think this is because moving the player left or right also sets the control rotation, thus they are fighting one another. If I could smoothly reset the camera is some other fashion I could then "SetControlRotation" after the player has stopped. This was the camera could rest smoothly behind the back and the player could continue in its left or right direction, only updating the control direction once all movement had ended.

I've tried everything I can think of and I'm dead-ended on this. Please check out the video my BP is based on that and I will also make a capture. Sorry for the long winded question, I've asked about this elsewhere with not much result. Thanks for any help!

alt text

Product Version: UE 4.19
Tags:
camerareset.png (76.0 kB)
more ▼

asked Dec 20 '18 at 09:04 AM in Blueprint Scripting

avatar image

bathorysthroat
15 4 5 11

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

2 answers: sort voted first

Alpha must go from 0 to 1, where 0 represents A and 1 represents B, so you can't use World Delta Seconds there. If you want to use Ease, you're going to need a Timeline with a Curve that goes from 0 to 1.

If you don't want to use a Timeline, try Rinterp instead of Ease. That runs on World Delta Seconds.

more ▼

answered Dec 20 '18 at 09:32 AM

avatar image

Tuerer
1.8k 12 7 8

avatar image bathorysthroat Dec 20 '18 at 09:58 AM

Thanks but that's not the problem, this setup does reset the camera, I just need some other way of smoothly doing so without "SetControlRotation" because if the player moves while resetting the camera will keep spinning.

avatar image Tuerer Dec 20 '18 at 10:05 AM

Try disabling the camera rotation control with mouse/movement until the camera is reset. For example, if you use a Timeline, when you press the reset key, set a cutom bool variable to False, and when the Timeline has finished playing, set it back to True. And add a branch between the mouse input (or whatever keeps moving the camera) with that bool variable. If you make a Timeline length about 1 second, which is quite enough to reset the camera position with a decent degree of smoothness, you can easily disable the camera rotation by anything else than the Timeline, and it won't adversely affect the player experience.

Edit: another thing: your setup seems to work because you don't save the initial rotation to a variable before starting to reset the angle, but that doesn't in fact work as you'd like, because the rotation never actually reaches the target angle, it just gets closer and closer, because for every iteration you take the current angle and value A. And therefore your reset rotation never actually finishes.

I really suggest using a Timeline, saving the rotation to a variable before starting to reset the camera position, and working with the Ease node where value A is that initial rotation variabe, value B is the target rotation variable, and with the Timeline curve as Alpha. Maybe in this case you won't even have to disable rotation caused by movement, but you'll have to check that.

avatar image bathorysthroat Dec 20 '18 at 10:42 AM

Thank I'll give it a shot I've tried once before by getting the camera rotation (A) at Begin play but I don't know exactly how I would get the cameras target rotation (B) that's why I'm using player forward arrow. How would I do so? Also, is event begin play to getworldrotation (camera) a good way to grab the cameras initial rotation?

avatar image Tuerer Dec 20 '18 at 10:56 AM

What I meant by initial is the current camera rotation at the moment when you press the reset key. The target is the character rotation, you're right about that.

avatar image bathorysthroat Dec 20 '18 at 11:12 AM

Ok I did that and added the timeline but I'm still getting the spinout issue when resting while the player is turning left or right.

avatar image Tuerer Dec 20 '18 at 11:46 AM

I gave it some more thought and realized I've mislead you, sorry about that. The Timeline won't work right if your player turns during the timeline.

You can try using Ease as you intended from the very beginning, but what I think you should do is after the Set Camera Rotation — check if the difference between the current camera angle and the target angle is less than a certain threshold, like 3-5 degrees, and when it is, close the Gate (unfortunately I can't see what's after the Set Control Rotation in your blueprint — by the way, why are you using Control Rotation, not Camera Rotation?). The thing is, as I mentioned earlier, the angle never reaches the target angle, and I don't know exactly when you close the Gate and stop executing the Set Rotation command.

avatar image bathorysthroat Dec 20 '18 at 11:55 AM

Okay well after the Set control I had a delay the length of the blend that then closed the gate. But with the timeline in place, I don't seem to need the delay. I'm using Set control rotation because that's the only thing that properly moved the camera in the way it is meant to. If there's a better way I'll try it umm I also tried setworldrotation as well as setrelativerotation (just to test to see what happens) on the camera itself but all that does is move it to an awful position.

avatar image Tuerer Dec 20 '18 at 01:35 PM

Got it. I thought some more (which is quite difficult with no engine at hand) and came to a conclusion that a Timeline should work as long as you save Current Rotation to a variable, but use the Character Rotation as B without saving it to a variable. Thus even if you rotate the Character in the process of TImeline work, it wil just speed up/slow down the rotation offset, but the camera should be exactly where you want it at the end of the Timeline.

And you won't need any Gate or Tick (or Timer, whatever you use for the Gate Enter pin). So you only have to Play the Timeline once when reset key is pressed.

Another thing, how does the camera normally rotate? How does it depend on the Character movement or keyboard/mouse input?

avatar image bathorysthroat Dec 20 '18 at 08:02 PM

Ok I already have the Current rotation saved into A and I'm already using Characters Rotation into B, but that doesn't seem to work speedup/slow down the rotation offset like you mention (not sure what I'm missing there). I'm using a gate because it's set from a tick to check if the Controller rotation and players world rotation are not within 2 degrees of each other then the gate is open to reset at button press. The camera rotates by using the mouse or right stick on control. I could be wrong but I really feel like the Set control rotation that resets the camera is fighting with the players left and right movement (A/D on keyboard) and that is why the camera can not reach its destination. but if that is the case I have no other way to move the camera in the same way without messing with control rotation. Hope that makes sense.

avatar image Tuerer Dec 20 '18 at 10:29 PM

Okay, I tried to recreate your setup and I think I know what the actual issue is. The thing is, when you start resetting the camera rotation and the Character is still rotating, at some moment it might happen that the opposite direction becomes the shortest one, and the camera shakes and jitters, and having the Shortest Path on Ease on or off doesn't make any difference.

How to deal with that... I can't tell you now. But I'll be definitely thinking about is a lot more. If you happen ti find the solution, please do write it here. I'll do that too, if any.

avatar image bathorysthroat Dec 21 '18 at 06:56 AM

I'm stumped for now as well so, for the time being, I have the game set up to have the camera follower the player when the player is moving (like a Zelda or Mario 64 camera) and if the player is standing still you can then reset with the Ease as long as the player isn't moving. This would be good enough for now but I'm stuck on something. I need to be able to reset the camera position after a button press while the camera is moving, I'd like to Ease but it doesn't have to if I can't get it. The reason this is so important is that if the player is running toward the camera and unable to reset camera position whilst moving, the player could potentially run head first into enemies or other hazards..

avatar image Tuerer Dec 21 '18 at 05:06 PM

After doing some thinking, I came up with this: alt text

Basically the idea is that upon pressing the reset key you snap the Camera Rotation to the Character Rotation (in my case it's Attach Actor, but in your case I believe the Camera is already attached to the Character, so you only have to lock its rotation relative to the Character), and then you execute the resetting sequence.

The value in the Alpha controls the rotation rate, you can play with that to reach the desired effect. The branch condition sets the threshold angle value that stops the rotation. After the rotation is stopped, you unlock the Camera Rotation from the Character Rotation again.

The Timer represents a tick. I set it to fire 50 times a second, because Event Tick frequency may change, but the Timer is more stable (provided that your fps is higher than the timer fire rate).

One drawback is that the rotation rate is not constant, it starts fast and slows down, but maybe that's an advantage, depends.

Don't mind the names ans the rotation nodes, I actually did it all with just cubes, you can rotate the camera using the controller as you used to; what I wanted to show is just the math and the attachment/detachment part.

camturn.png (279.6 kB)
avatar image bathorysthroat Dec 21 '18 at 06:29 PM

Ok So I tried this what you have, I was a bit confused because like you said my camera is attached to the player so I can't use SetActorWorld so I used SetWorldRotation. This way of doing does rotate the came in the right direction but does not move the camera to the correct location behind the players back (does yours?). I tried setworldlocation of the camera's location to the location of a box (attached to the player) set in place to act as a position of where the camera should end up. This kinda moves it but often next to the box and depending on the angle the camera was reset from it can also screw up the roll. I have no idea : (

avatar image Tuerer Dec 21 '18 at 06:46 PM

Your camera is attached to the Character, but as I understood the Camera Rotation is independent of the Character Rotation, is that right?

If we set everything else aside, is there a way to lock the Camera Rotation to the Character as it is at the current moment of time? Like, foe example, the Camera look to the right side of the Character, and when you lock it, no matter how the Character moves, the Camera always stays at the same side of the Character?

avatar image bathorysthroat Dec 21 '18 at 07:05 PM

Yes, the camera rotation is indeed independent of character rotation. I'm not sure but why would I need to lock the cameras current rotation (the place where the camera is just before reset if I'm understanding you correctly).

avatar image Tuerer Dec 21 '18 at 07:48 PM

Yes, that would be where I used the Attach node. If you snap the camera to the character, the reset rotation should work just right.

avatar image bathorysthroat Dec 21 '18 at 08:00 PM

I don't understand, my camera is already child to my players mesh.

avatar image bathorysthroat Dec 21 '18 at 08:10 PM

I set up the attach but that just makes it so I can no longer move the camera freely. I should be able to move the camera around and for example, if the player is running toward the camera/hit reset button and the camera goes behind the back.

avatar image bathorysthroat Dec 21 '18 at 08:24 PM

https://www.youtube.com/watch?v=VCTurcB5bcY

Not my video but essentially this Except I would need to also work the same if the character is moving. It's done in Silent Hill 2 if you've ever played that. and quite a few other third person games. I'm just posting this to make sure there's no confusion. I wish I could look at how they were done because you would think something like this that so many games use would be more accessible to learn.

avatar image Tuerer Dec 22 '18 at 07:08 AM

So that's a standard TPS template, I see; for some reason I was thinking you have made something custom.

As I understand it, in TPS movement is based on the Camera rotation, not on the Character rotation; and so it happens that when you press D and the Character moves right respective to the camera, and then you start forcedly rotate the Camera while still pressing D, at every moment of time the Character turns mode right, and so you get yourself into an infinite loop.

What I can suggest you now is making the reset quite fast, like 0.5-second long, with disabling input before it starts and enabling it right after it's done.

avatar image bathorysthroat Dec 22 '18 at 08:29 AM

Hmm good idea I'll try that and get back to you.

avatar image Tuerer Dec 22 '18 at 08:34 AM

But mind that when you disable input you have to disrupt the connection from the movement axis input to character movement; just set a branch with a bool variable after the input node. Otherwise if you disable input before the movement key is released, the character will continue moving even if you release the key after the input is disabled, because the controller will never receive the key release signal.

Edit: or use Set Ignore Move Input

avatar image bathorysthroat Dec 22 '18 at 08:54 PM

Ok so what I did now was shorten the timeline, SetIgnoreMovement (True) before the timeline, then to false after the SeControlRotation. But still spins out fast and if I'm walk toward the camera and reset the camera shakes until the inevitable turn around of the player character.

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

Hi!

I've been struggling with this exact same issue for a few days as well, and I finally found the solution.

The key is to set OrientRotationToMovement variable (of the Character Movement component) to false just before the rotation, and then set it back to true when it's done. That's the only thing that worked for me, I hope it will help you too :)

more ▼

answered May 12 '19 at 10:27 PM

avatar image

Dinaga
1 1

avatar image bathorysthroat 4 days ago

Thanks, I'll try it out when I have a moment to get back to it I just spent the last four months building an inventory system.

(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