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.
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.
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.
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.
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.
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.
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 .
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?
the problem remains still .
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).
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.
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.
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)
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
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 ) 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.