Lerp rotation problem.

hi,I want to rotate an actor to face a moving target.
I need it arriving in a given time.
I use a timeline,but I met a problem,hope someone could help me figure out.
here’s the rotating BP.

the video showing the problem:


As you can see,if the target(the character) is at a certain location.
The rotation will suddenly jump to …(I don’t know how to explain…my English bad sorry)
if the target stands still.it works properly.but I need the target to move.and the little airplane rotate to face it in a given time.how do I achieve that?
Appreciate the helping.
please ask me questions if the info is not clear.

1 Like

Hey, Bao!

Okay, so this is the front of your object, yes?:

If so, your function is doing what it is supposed to be doing!

The problem with a TIMELINE is that a TIMELINE has to complete an action before its clock runs out. That’s why it snaps so quickly when your character moves; it has to arrive at the target before time runs out.

So, what you’ll want to do instead is use a tick function that constantly tracks the movement of your character.

Your function will look something like this:

1 Like

I respectfully disagree with your analysis, the issue comes from the fact that the initial rotation stay the same for the entire duration of the timeline, so at the begining perhaps it made sense to rotate clockwise to get the shortpath, but at some point it made more sense to rotate counter clockwise from the initial rotation compared to the new rotation, hence the jump in rotation.

1 Like

We are saying the same thing but in different ways.

If it needs to take a shorter path to do so, it will.

Here is a beautiful drawing of the issue.

If you don’t mind losing the linear aspect of the interpolation then you only need to use GetActorRotation instead of your InitialRotation in the first pin of the LertRotator node.

Hey @baobao4435!

They’re both right, really.

You should uncheck shortest path when using a dynamic end but a static start rotation, this is exactly what happens.

Because a timeline will run it’s course unless the stop execution pin is used, and it insists on finishing, if you do this, once the timeline finishes it does not matter what direction it turns it WILL end the timeline facing the target. But with the shortest path option, it will not find the shortest path in every frame.

Also- you can delete your first Lerp node if you want. It isn’t doing anything here. :slight_smile:

2 Likes

Usually when tracking a moving target it’s better to use RInterp, but you loose the precise control over the timing…
image

3 Likes

It’s such a strange feeling debating with someone who is actually on the same side as you, but doesn’t realize it.

Anyway, tested and updated:

Now you can adjust the speed at which the enemy tracks by changing the INTERP speed.

If you NEED it to arrive in a SPECIFIC TIME use @Mind-Brain solution.
If you want it to lag a little, there’s mine.

Good luck!

1 Like

@Leomerya12 , @Sly.Sk , @Mind-Brain .thank you guys.it’s rarer to see so many help in a short time.

Yes.it looks like the shortest path problem,but I already tried that before I post the question,and I tried again just now.no matter I check or uncheck the Boolean,the result is the same.and the jumping only happens when the player is at the location:


And if I use interpretation in tick,it’s like never catch up the target,which is not I want.
I need it to arrive at given time…that’s why I considered a timeline.
thanks you all again .

1 Like

Yes, this is exactly why I described the issue the way I did; because no matter what, it needs to finish the function BEFORE TIME RUNS OUT. So, you going to get snapping no matter what you do with a timeline. The exact reason why is irrelevant.

Anyway, with that out the way, let’s see what we can do…

To be clear, do you want the object to rotate at a constant speed or should it rotate a little faster sometimes?

1 Like

the problem remains still :sob:.
and I think the first video doesn’t clear so I record a new one.

I exposed the timeline event to call on editor so you can see when I call it.
here I unchecked the shortest path.but it still does the thing.and only happens at a certain location (right corner).

Okay, here is what I came up with.

Hold onto your butt, because this is a long one.

What this does is it combines the two INTERPS. You get the nice, smooth RINTERP_TO in the beginning, and then once the enemy has “eyes” close enough to the target character, it gently snaps into position:

So, for example, if the ENEMY’s rotation (Z-Axis) is 120, and the CHARACTER’s rotation (Z-Axis) is 45. The ENEMY will start by using the RINTERP_TO until it is around 3 degrees away from its target. This prevents the VERY LONG time it takes for the RINTERP_TO node to complete. So, at around 48 degrees, it jumps to the next function, which has the R_INTERPTO_CONTSTANT, and this function gently snaps the ENEMY’s “eyes” on the target CHARACTER.

If the player goes past 3 degrees, then it reverts to the R_INTERPTO function again, until the 3 degree threshold is met.

A video (uploading):

1 Like

2 Likes

Nice one @Leomerya12
I hope you don’t mind the competition :stuck_out_tongue:

On my end I got something nice with this :smiley:

RInterp

It’s a garantee to align with the target at the end of the timeline duration. Basically what I’m doing is using FInterpToConstant to constantly Interp with the target, but I change the speed alogn to match the remaining time of the timeline.

The only issue (if that’s a concern) as showned in my second example in the gif is that it can change direction if you go all the way around it. I’m lookinginto it.

2 Likes

Got it working with an interpolation of fixed duration, and which preserve the direction of rotation. The only issue being that if you switch side in front of it it will stick to the given direction and go full circle x)

RInterp

2 Likes

You could basically merge the two behaviors by changing direction if the character switch side in front of it. So with this what you get is:

  • Interpolation of fixed duration
  • If character switches from behind, it keep the same rotation direction
  • If character switches side in front of the turret, then the turret changes direction

RInterp

2 Likes

So to summarize my findings, all of which lerp rotation under a fixed duration:

Simplest solution, favor shortest path meaning if switches direction if you go around it from behind

RInterp

.

This one will stick to the initial rotation direction, and stick to it no matter what so it can go full circle if you switch side in front of it

RInterp

.

Merge of the two previous solutions, it will keep the rotation direction if you go behind it but will switch rotation if you switch side in front of it

RInterp

Of course, all can be adapted to be used without a timeline and with a timer/on tick like in the other suggestions, it depends on what you need.

3 Likes

This crap is difficult enough without adding competition to the mix.

I’m here to help and be helped.

That said,

Your function is PERFECT for tracking missiles!!!

I’m stealing your work, and there’s absolutely nothing you can do about it.

3 Likes

That’s the way to go about it :heart: Take anything you want it’s free.

2 Likes

hi,sorry for late reply,because I took some time to learn your code.and tried to iterate it to 3d rotation(my fault,I didn’t point out that I need 3d rotation :joy: ) and @Leomerya12 is right,I hope to make a missile.

Your code looks perfect,thanks.
but I find if it rotates at 3d.it doesn’t go the shortest path.

I think it might relate to the r interp to constant.
here is video showing how it goes.


in video above.it tends to match pitch first,and then yaw.it’s not shortest path.making it look less beautiful then Lerp node…(of course totally personal opinion )
the code:

I’m not sure if I’m doing it right.I’m especially bad at division.until now I couldn’t figure out what “angle/remained time” means…
and I haven’t tried the second and third method.I still need time to digest.