0
\$\begingroup\$

So I'm working on a tower defense type of game and I have a rotation set up that is supposed to follow a chosen enemy. What I'm seeing is when the enemy comes from the left the turret turns quickly to face the enemy quickly. But when the enemy is on the right it goes much slower and doesn't actually "face" the character until much longer.

In this image I have the game set to show the capsule when the enemy is "targeted" so I know which one the turret is supposed to be facing.Right now its set for closest to base so the enemy at the bottom of the circle is the one the turret should be aimed at. It had from the time the enemy entered the blue area from the right till now when its almost out to point at the enemy. But it still hasn't completely turned to point at the enemy yet. However when the closest enemy is on the left it has no problem turning to face the enemy quickly.

enter image description here

Here is the code I am using to turn towards the enemy. Any ideas on what could possibly causing this behavior? enter image description here

\$\endgroup\$
1
\$\begingroup\$

It's a bit difficult to accurately diagnose the problem here without knowing the initial transform (position and rotation, world and local) of each of these objects, but here are a few suggestions to maybe help narrow it down for you:

Suggestion #1

Have you tried to feed the rotation returned from FindLookAtRotation directly into the Target rotation of RInterpTo and in turn use that result as your target rotation in SetActorRotation?

I'm just going off memory but if I recall correctly, the FindLookAtRotation does the main work of finding your destination rotation. RInterpTo then just interpolates smoothly to that destination over time. Not sure if/why the Make/Break rotator nodes are needed at all.

Suggestion #2: Overriding actual yaw/roll values

It's possible that your turret's rotation does not actually equal zero for Yaw and Roll (X/Z). Have you tried setting the X/Z values of that final MakeRotator node to the actual X/Z values from your base turret? You would need to use a BreakRotator node on the turret's rotation and then take the X/Z values from there, instead of overriding them as zero.

Suggestion #3: Initial Orientation

Does the turret and these target_enemies have the same initial orientation? As a quick test, try replacing those target enemy "ship" actors with turret actors. Does the main turret have any trouble rotating towards other turrets (instead of ships)?

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ I tried that and it rotates on all 3 axis. Which I don't want since it's 2d. I also took just the y, made a new rotator from that and still has the same effect of not turning to point at enemies very well when they come from the right \$\endgroup\$ – Jason Crosby Jun 1 '18 at 23:16
  • \$\begingroup\$ Thanks, this is the kind of info I was looking for. Some other things I could try to see if it works. Suggestion 2 made things a lot better. Thank you for the ideas. It was a big help. \$\endgroup\$ – Jason Crosby Jun 5 '18 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.