AI Perception attachment
Hello, I want to attach AI Perception Component to characters head instead of capsule center. Does anyone know how to do it? I red somewhere that it can be done by making AIPerceptionComponent based class in C++ and adding functionality to GetLocationAndDirection function, but that was all. I'm not hardcore programmer and I guess that since AIPerception is in AIController, not in Character, that's tricky to do.
asked Jan 04 '18 at 09:21 PM in C++ Programming
As was pointed out in this archived post, AIPerception uses GetActorViewPoint to determine the Sight Sense location and orientation. Unfortunately, this function cannot be overridden in blueprints yet. However, you can very easily override it in C++ and update the actor viewport with the location and rotation of "head" bone to achieve the effect you want. Hence, if you really need this, you have to do a little bit of coding. It's not that difficult though. Here's a quick step by step guide on how to accomplish this:
This uses the default's Third Person skeleton and the "head" bone to update these Location and Rotation values.
That's it! Now go back to the Editor, and compile your solution. If you're already in the blueprint version of ThirdPersonTemplate, then simply open the ThirdPersonCharacter blueprint, go to the Class Settings and on the top right, change the Parent Class to this BaseCharacter. If you're building your own Character, then use this BaseCharacter as the parent and create a new blueprint from it (one simple way to do this is to find this C++ BaseCharacter class in the Content Browser, right-click on it and create a new blueprint class from it). Next, create an AIController, add the AIPerception to it, and enable Sight Sense. The Yaw angle of Sight Sense will automatically get updated as this Character turns his head.
Hope this helps.
Now it works as it should :) However I had to change RTS_ParentBoneSpace to RTS_World and Rotator() to Yaw, because it was keeping world rotation 0,0,0 when characters head was in default position, so vision cone wasn't rotating even with the whole character.
I thought it we'll be something more complicated :) Thanks for your help!
answered Jan 06 '18 at 01:02 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here