Download

Aiming 2d rotation with FInterp

Hi, I can’t figure this one out… I’ve tried rotators and other things which sort of works until you add the smooth interp to it, then it breaks down. It seems to me I should be able to get an rotation X only solution to work, somehow? I’ll take any solution, as long as it doesn’t flip on any axis (including its own local banking axis).

I’ve attached my current solution, the lovely image I’ve drawn shows (left) how the triangle (‘component to rotate’) is looking at ‘target location’, then if that ‘target location’ moves to the other side of the triangle actor then the ‘RotX_target’ goes from 170 to -170. It should go from 170 to 190.

I’m wondering if one has to create a system that just works in any numbers, so support for angles like 450 or whatnot.

My brain is fried right now so hoping for some help here. Thanks a bunch for any help whatsoever!

Hi man,
Rotation can be really hard to manage,

I use a dirty trick free from the quaternions , here how it works
I create a scene component and snap it to the target, now the scene component have relative location
and i can check his Y to know if is at right or left of Turrett.
And then i rotate the actor at “costant speed” using the time * direction (* optional_extra_speed).

Thanks for the reply, I do get my relative location by subtracting the target location from self so that might be something to consider.

I’m actually not quite sure what this is meant for? You are taking the relative Y location and add that to the Z rotation, I would not expect that work as a 360 degree 2d aim at function… if it’s meant to work in a 180 degree field then that’s different. :slight_smile: My function works well as long as the target doesn’t do a full 360+ degree move around the aiming actor.

I’m looking for something that will aim at a target in over 360 degrees and never flip. Imagine the target is doing ten loops around the aiming actor. The actor should try to keep up, and always pick the shortest angle to rotate to this target. When aiming downwards it will not as the target moves from the left side to the right of the actor, as I tried to draw up in my image above.

Can you explain what your use case is here?

Thanks again!

Hi man,

Yes my dirty solution works 360 , and never flip.
He choose always the short direction
need just one more check because ABS < 10 could be also behind the turret.
you should check the X too , is really more clear if you try to build it than explain it but:

Follow me building it so is a little clear.

I make the turret move toward the target with constant speed.
Using a transformation from, world to local position.

**Make a scene component **in your turret_ call it Target_local .
Be sure that is not root, just a child. so you can move it without moving anything of the turret. as you can see from my blueprint.
Now **if you move this Target_local to the right and left **of the turrett, you will see that his location is 0 when is at the center.
And positive when left or right, and viceversa negative on the other side.
As you can see from the blueprint, i set the Target_local position using the “world position” of the real target.

The turret get the “local position” of the real target.
Local mean “Based on himself” so the Target local position is a vector from the point of view of the Turret .
Using this trick i get to know if the Real target is on the right (+Y) or on the left (-Y) or higher (+Z) or lower (-Z) than my rutterr.

I made a check if the Y is minor than 10 i decided that he is in front of me so i can shoot.
If the targetlocal have higher Y or Lower than i rotate the turrett.
To rotate her i get the value of Y, just the truncate valor , so -1 or +1, for add or subtract a Value for rotation (the time delta)

**Just play with setting the scenecomponent on the worldposition of the target and play with it.
I tryed to be clear but probably mmessed all up **

Thanks for the detailed reply, I will def check this out as soon as I get back to my project! :slight_smile: Sounds like an interesting solution.