Rotation character towards controller rotation when key is pressed. (character spins out of control.)

Hey there, what I’m trying to achieve is a control scheme similiar to a lot of third person games, Dead Space comes to mind. In those games you can essentially orbit around the character when not using ADS, which is what the third person example starts out like, now when you use ADS in those games the character will rotate towards the cameras facing direction and will now rotate with the camera until the button is released.

I have managed to get it how I like, but the problem is sometimes the character will spin madly trying to find the controllers direction, I have a feeling it might be because the controller isn’t clamped from 0-360?

I have manually tried to clamp it between the break and make rots for the camera rotation, but that didn’t work and made the character snap.

You can see how I have it set up in the blueprint, I have also named the output track so you understand whats going on in it.

Here is a terrible .gif that sorta shows what is going on.

1 Like

Yeah this does help, and it turns out I’m completely blind and the rotator lerp actually has an inbuilt function for this, it’s a bool tick box called shortest path

Using this seems to have fixed the problem completely.

Thank you kindly for your help though.

I think the problem is the engine tries to rotate the character in only 1 direction.

ie If the charcter rotation is 30degrees and the Control rotation is 290 degrees, The engine updates the rotation of charcter like 30…60…90…180…200…250…290 This results in a big sweep (260 degrees). But a better way to achieve this would have been 30…0…350…300.290 which is a reasonable sweep (100 degrees).

So try to change the direction of rotation based on which difference is smaller and rotate character clockwise or anti-clockwise accordingly

The problem appears to be coming fro Lerp, which tries to do it in only one direction.

A simple trick will be to use negetive rotation. ie instead of telling the Lerp to transition it from 30 to 290, you say transition from 30 to -70. I am not sure this will work, but its worth a try