Im currently in the flying blueprint template messing around in blueprints trying to create a mechanic where upon hitting a key (in this case its Z) the ship will pitched up 180 degrees (a half loop) for you and will make the ship face the other way as a sort of evasive maneuver. However, no matter what I try, it’ll only rotate by 90 degrees and no more. I have tried most of the rotation nodes like set actor local rotation but that just causes the ship to go mental. Any ideas?
I think you are experiencing Gimbal Lock.
This is a weakness in the Euler Rotators used by Unreal and most 3D engines.
I have heard there is a way to overcome it by using Combine Rotators node, supposing that it internally uses Quaternions to calculate the output Rotator. Perhaps that will work (I dont know for sure) to take your current rotation, and then put the added amou t to rotate on the second input of the Combine Rotators node and then do set Actor Rotation from that combine Rotators output.
Let me know if that works.
are ypu able to accomplish the same manuever by directly controlling it rather than an automated lerp? If not then it is probably gimbal locked
You want the ship to do a 180 from its current rotation, right?
In your blueprint you’re simply setting the pitch to 180 degrees instead of adding 180 degrees to the ship’s current pitch.
oh wow. good catch! Perhaps jt is not gimbal lock after all
Well I was trying to have it lerp to the 180 rotation over a short amount of time instead of an immediate snap to 180. Unless you mean something else? How would I add it instead of setting it?
Could you show me with an image or something? Sorry, I’m not the most skilled with ue4.
I have tried changing the number to 270 but to no avail. It just is not happy with going past 90 degrees and you are right about Add To Control Rotation part. I’ve seen fixed that mentioned it but that node is normally for when you are inputting the movement itself, not done automatically with an event tick. In what way do you want me to combine the rotators? I’ve got a variable that now records the starting rotation. Do you want the starting rotation to be A or B?
Forgive me if I am wrong
Not exactly.
There are lots of different ways to rotate an actor:
SetActorRotation uses absolute rotation values (world rotation)
SetActorRelativeRotation is a little different
AddToControlRotation will change the rotation values on the Controller and then the controller will decide how to apply that to the Pawn. It will do this incrementally though, rather than setting it to a specific rotation. This is great for controlling rotation with a mouse axis but not good for choreographed movements.
If you CombineRotators from your GetActorRotation to all the math you did on that Actor’s rotation, it’s going to accumulated extra rotation amounts. You should combine it with the starting rotation amount to aid the lerp.
But you only need to do that if you’re getting gimbal locked (you might be but I don’t know).
@Velrin is saying you might just be putting in the wrong target rotation. Try going back to your original way of doing it and changing it to 270 degrees instead of 180 and see if it gets past the vertical, before trying anything else.
CombineRotators first applies A and then B on top of the first one from A using quaternions (which rules out the gimbal lock problem if that’s what’s happening to you).
So I think maybe it will work to apply first your Starting Rotation on the A, and then the change in pitch on top of that. But maybe don’t use RInterpToConstant. Instead maybe try a single float value interp from 0 to 180 and feed that into the Pitch Component of the B on CombineRotators, and keep the other axes on B zero (because we don’t need to alter the Starting rotation by anything but pitch, right?)
I don’t know if this will work but I think we should try it.
Also make sure your Pawn is not a Character class or using CharacterMovement component, as that will limit your pitch to not be able to flip upside down. At least it seems to me that it does.
The character is definitely a pawn and does not use any type of a movement component. I assume you mean something like this?
Well I did that but split up the starting rotation so it only combined the pitch from both A and B. It did the exact same thing as every other attempt ever has but refuses to go past 90. 90 is just its limit. Changing the plus from 180 to 270 still wont let it go past 90.
Yes that looks like how I would try to do it. I’m sorry that’s not working.
Are you able to pitch up until the ship turns upside-down if you are directly controlling it via InputAxis events rather than lerping the rotation over time?
If you can get direct pitch control to flip the airplane then we know it’s not something else wrong with the airplane stopping it from rotating past the 90 degree mark; instead it must be something about how we’re doing the math. Let’s rule out that possibility if you haven’t done so yet.
Yes, I can pitch the ship however much degrees I want in any direction but as soon as I use set rotation nodes of any kind or add control rotation to automate it instead of using input axis, it always tends to cap at 90.
Maybe before setrotation or setcontrolrotation node or addcontrolrotation node, you can test whether pitch is equal or Nearly Equal to 90 and if it is, set it to either 89.999 or 90.001 degrees instead, depending on what side of 90 the rotation is at before adding the further rotation. This might prevent the locking. I have overcome this problem before but.i dont remember how. i remember trying something like that though.
So you’re saying to set it to a very small number above 90 before it actually reaches 90 to bypass the locking?
Yep. You can experience gimbal lock just in the level editor viewport by selecting an Actor, then right-clicking it and selecting "Pilot " from the pop up menu, and then holding the right mouse button to rotate it up or down as far as it will go, then trying to rotate another direction. It locks up at 90 degrees and changes the definition of all the other axis rotations to be all confused.
I’m not always 100% sure of what I’m doing but what I do know is that this gimbal lock nonsense is really irritating when i’m trying to have some fun and test stuff with the engine. I made a piece of code which does what you said, setting the pitch to be above 90 before it reaches more than 89 and the game seems to detect im trying to bypass the gimbal lock and pushes the number down before 90 again.