Resolved: Confine AI rotation to 2 180 degree yaw values

Hi everybody.

So I’m working on a classic arcade beat’em up style game (eg: Double Dragon, Final Fight, Streets of Rage) and I’ve run into an issue with the AI rotation. What I want to do is have Yaw set to only 0 or 180 depending on movement along the X axis while still allowing the characters to move along the Y axis but not actually rotate.

I have this working for the player character but I’m not sure how to get the axis values for an AI-driven pawn. I was thinking I could get the Forward Vector and then set the rotation based on >90 & <270 = Set Rotation 180 and <90 & >270 - Set Rotation 0; but getting things to work just hasn’t been happening for me at this point.

Any ideas?

Hello,

Have you tried disabling the “Use Controller Rotation Yaw” checkbox in your AI Pawns?

285427-ai-rot.png

?

Hey, thanks for the response.

Yeah I have that disabled.

I seem to be stuck with one of 2 types of rotational functionality; the ai characters will rotate normally and always face the direction they are moving, or they will be stuck facing a single direction and not rotate at all.

Are you using Behavior Trees? If so, on the “Move To Location” node there’s a checkbox that will allow strafe movement to the movement location. By enabling strafe movement you can freely rotate your characters to the direction you like them to face.

I didn’t realize there was much on that BT node to play with!

I’ll check that out after work tonight. Thanks for the suggestion and I’ll let you know how it goes.

So I tried toggling the Strafe option in the MoveTo AI node and that has stopped the automatic rotation (Thank you), but I can’t get the AI to rotate; which in this case I basically mean flip 180 degrees along the Z axis when the player it is approaching moves behind it.

Below is the service I’ve been trying to get to work to produce the rotation but it doesn’t appear to do a damned thing unfortunately. I feel like I’m really close but just can’t get past this last hurdle…

Have you verified that the blackboard value is valid? Moreover, in your code you’re checking if the needed rotation has a yaw value between 90 and 270 degrees. Then, in the second branch node you’re checking if the yaw value is either < 90 or > 270. If the code executes successfully, you have missed an important check (in your case) , which is what happens if your yaw value is either 90 or 270. In that case, the “False” path of your 2nd branch node will execute and you have placed no code there.

So to sum up, can you verify that:

  1. You have a valid blackboard entry
  2. The execution path actually attempts to rotate your pawn?
  3. The above task is successful (You need to call the “Finish Execute” when you want the task to finish). With that being said, try calling “Finish Execute” function when you’ve set the new rotation to the AI Pawn.

Last but not least, based on your original question I would suggest to move the above functionality in the “Receive Execute AI”.

Thanks again for the reply, I really appreciate your help with this.

I had spaced on making it a Service rather than a Task, so I switched it over so it’s now using a “Receive Execute AI” and was able to add the “Finish Execute” onto the end.

  1. I verified that the key is valid and that the vector value being returned is being updated using an is valid and some “Print String” nodes; all looks good there.

  2. The path is executing through to the “Rotate” nodes. Verified using Breakpoints. I also tried swapping over my “Set Control Rotation” nodes to “Set Actor Rotation” since I have the pawn set to ignore control rotation currently; but that didn’t change the result which is currently that the enemy pawn isn’t rotating at all.

  3. I’ve added the Finish Execute.

As for the ignoring the 90 and 270 values, I left that intentionally at the time to help troubleshoot what was happening. I’ve added another “Print String” for the time being to make sure that it’s atleast reading the “Look at Rotation” correctly.

I haven’t been this frustrated with something game related since the first time I fought Shao Khan in MK2 lol. Here is my updated Task BP.

What is happening in your Behavior Tree when you’re executing the task? Is it stuck on a “pending” status or is it executing successfully? Can you show us a screenshot from your BT?

Here is the base of my BT. I pulled out the follow-up tasks as they’re never getting triggered. So what I’ve found is that when I have the Rotation task first in the execution string, it loops endlessly with the Move To never firing. If I put it second in the tree, it gets called and the sequence continues on but no rotation ever occurs.

I’ve also found that when I run debugging now, the task gets executed in a straight line from the Event Start through the Is Valid?, then the Print, the branch, the top Set Rotation and then Finish without ever altering that execution path. To top it off though, the Print isn’t giving me the vector value any more.

Holy ■■■■ I finally figured it out!!

It was a combination of a few things that I had done wrong. First, when I was getting the BB Value as Vector, I needed to get it as an object, then cast to the BP of the contained pawn and get it’s location instead.

After that, my directional checks weren’t narrowed enough so that some where read not as intended. And finally, to get the rotation to occur during the move and be updated, I needed to use a Simple Parallel node rather than just a Sequence in my BT.

Thanks so much for your help on this Orfeas El. The questions and suggestions you made are a big part of the reason I was able to solve this!