x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: UE 4.17
Tags:
more ▼

asked Jan 04 '18 at 09:21 PM in C++ Programming

avatar image

RushingVice
8 1 2 6

(comments are locked)
10|2000 characters needed characters left

3 answers: sort voted first

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:

  1. In the Content Browser, click on the green button Add New > New C++ Class. Select Character and name it BaseCharacter.

  2. Th Engine will take a short moment to create this class and recompile the solution. If you're on Windows and have Visual Studio installed, it will open automatically. Once the Visual Studio opens, go to the BaseCharacter.h and override GetActorViewpoint method as a public function by adding the following line within those curly brackets:

     void GetActorEyesViewPoint(FVector& Location, FRotator& Rotation) const override;
    
  3. Go to BaseCharacter.cpp and add these few lines:

     void ABaseCharacter::GetActorEyesViewPoint(FVector& Location, FRotator& Rotation) const
     {
         Location = GetMesh()->GetSocketLocation("head");
    
         Rotation = GetActorRotation();
         Rotation.Yaw -= GetMesh()->GetSocketTransform("head", RTS_ParentBoneSpace).Rotator().Roll;
     }
    

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.

~Vizgin

more ▼

answered Jan 06 '18 at 10:40 AM

avatar image

Vizgin
1.4k 10 10 17

(comments are locked)
10|2000 characters needed characters left

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!

more ▼

answered Jan 06 '18 at 01:02 PM

avatar image

RushingVice
8 1 2 6

avatar image Vizgin Jan 06 '18 at 01:17 PM

You're welcome :-)

Yes, you're right. I missed the part that the bone coordinate system doesn't get affected by the root motion. I'll update the code soon.

(comments are locked)
10|2000 characters needed characters left

Hi,

Maybe these two answers (link1, link2) can help you achieve what you want :-)

more ▼

answered Jan 04 '18 at 11:10 PM

avatar image

Vizgin
1.4k 10 10 17

avatar image RushingVice Jan 05 '18 at 08:31 AM

Hey, thanks but it's not what I want. I don't want custom points on sensed character (well, I want, but I have that already). What I want is when my AI turns head, its vision cone rotates with it. Now its rotating only with whole character.

avatar image Vizgin Jan 06 '18 at 10:14 AM

Oh sorry, I misunderstood your question. Unfortunately, afaik this cannot be done in blueprints. The comment section doesn't like Code blocks so I'm posting an updated answer with some steps on how to do it in C++.

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question