NPC Looking At Camera After Trigger Event

Hello,
I have been looking for a solution to this for a while. It sounds like a basic question, if someone asked before, it is because of I don’t even know how to search for it, sorry about that

I am trying to make my NPC interact with the player. When the player gets into the box trigger, I want my NPC to look at the camera like in the Content Example projects animation level “Yaw and Pitch” section.

Edit:
I have improved my nodes so far. I only need to find a solution to connect the “Make Rot” value from Level Blueprint to my characters Anim Graph to override “Transform Bone” values. I have researched and it seems like connection between Blueprints will be implemented later. Is there a better way of doing this? For now, characters body faces the camera from the root

Thanks!

Level Blueprint:

Anim Graph:

Thanks so much!

Hi,

“it seems like connection between Blueprints will be implemented later”

There are official tutorials talking about Blueprint Communication, just take your time to watch them.

So,
Your Character is doing a rotation based on its root only because:

  • you’re calling SetActorRotation in the Event graph.of the classic blueprint.
  • The pose in the anim graph is just reflecting that fact.
  1. Promote your result from MakeRot Node into a Rotator variable in the classic Blueprint.
  2. In your anim blueprint, use Event Blueprint Initialize Animation Node to promote a reference to your classic blueprint. This can be easily done thanks to the Try Get Pawn Owner Node.

In the above example, I’m giving to the AnimBP an access to the Turret_BP.
Turret_BP is doing all rotation computations in it’s event graph.

The AnimBP is “only” getting the updated value while posing…

  1. Get your Rotator variable in the Anim Graph and pass it to the Transform (Modify) Bone Node.

Here is a basic working example with a classic blueprint exposed to the Anim one to control the rotations of 2 bones in a model.

Note that a Layered Blend Pose is used above because I’m transforming more than one bone.
You may take a look at that at some point.

Hope it helps.

By the way, I forgot to say that you need to transfer your Level Blueprint logic to your Character Blueprint.

Hi,
Thanks so much, for your reply! Now that I learned communication, I can study BP’s better. I have another question about this tough:

  • In my EventGraph, is everything correct? Couldn’t find any proper Cast To node, tried Actor instead
  • In AnimGraph, I can’t make the Rot Value with Target input, therefore I can’t connect nodes together.
  • In your example there is a Turret_BP, I guess it should contain those “MakeRot” things within, how can I do that?

Hi,

How many Blueprints are you working with?
I suppose you have only one Blueprint used for the Character, which is AnimationBlueprint.

Yeah, now that I transfered my Level BP nodes to my characters BP, I have one blueprint with anim and event in it. I messed up a lot it seems, thank you so much for helping me! I am grateful

Hi,

In that case you don’t need to try to get a Pawn owner that doesn’t exists.
I had to ask you this since the begining, I’ve put you in the wrong direction sorry :slight_smile:

So,
you have a character and a trigger box (manually placed in the level) wrapping it, you are controlling a camera and when you overlap the box, you want the character in it look at the camera?

In your case, with only one Animation Blueprint, how your Event Graph is aware of the trigger event? It was aware because the logic was put in the Level Blueprint. But now? How the Anim Event graph knows when to start computations? (Maybe you can add a custom event in your event graph and call it from you characterMale node in the Level Blueprint)

Usually it’s better to have a Class Blueprint to wrap your mesh and a AnimBlueprint linked for skeletal related animation when apply. In your Class Blueprint you can attach a lot of different components to your mesh, like a trigger box for example. In such setup you can use PawnOwner node to get the Blueprint instance in the linked AnimBlueprint.

Anyway, lets’ try to have the animation working for instance, as the logic there should still be valid.

First, if you want to see something happening in your current event graph, you should pin the output of the SET ActorValue in the input of SET RotValue.
These pin are executions flows controllers, no pin, no party :slight_smile:

So,
In your AnimGraph you can remove the ActorValue node. The rest should be ok. The base pose is the head and you’ve choosen to weight half the rotation for the neck.

In your Event Graph you can remove all the Cast flow, you don’t need that.
You just need to find the location of the camera and the character.
The CameraManager Node can be used for anything related to the Camera.
For the character, it’s better to retrieve the location of the head bone to have a better target vector because ActorLocation is the Root location of the Object and in the case of a character, I don’t think the root location is the best one regarding aiming :slight_smile:

Try that to see if it works.
If it’s the case, you’ll probably notice that the head is facing the camera without any feeling of animation at all. This is the moment to introduce the time factor and interpolation as well.

RInterp Node, that’s it.
You need to pass the time elapsed since last frame, which is always given in the output pin of the AnimUpdateNode.
You have to choose the speed of animation, hence the interpolationSpeed pin that should be the degrees/second you want your head rotate.
There is also a RInterpToConstant Node with the exact same parameters.
Play with it to see the differences in the animation between both nodes.

Hi again,

Thanks so much spending your time to my crazy issues

I did try everything but I get log errors now. Even trying to do it in a new, already designed scene (Reflections) to see if I missed something major. This time I am sharing whole screens in order to see whats wrong better.

I have a question before asking about the issues tough,

  • Doesn’t “Transform from Bone Space” in Event Graph and “Transform (Modify) Bone” in AnimGraph will do double rotation?
  • In Event Graph there are “Get Player Character” and “Get Player Camera Manager” nodes with both Player Index value of 0. Isn’t it supposed to be the player? Aren’t we supposed to make one of them the mesh we want to rotate it as target to “Transform from Bone Space”?

Okay, here are some issues I have found:

  • In Anim Graph, even if I change the Yaw value manually, character joint doesn’t rotate at all
  • In BP Panel preview, it says “Previewing BP_Raynor_C” and I have no idea what that _C suffix is
  • I am getting such log errors:

Event Graph:Looks quite the same: I only changed the Bone Name to my joint

Anim Graph: I applied (Still not sure tough) the Make Rot value to Rotation

Scene Character Details: I use the very same animation BP in animation slot
(Anim Blueprint Generated Class) and Input is Disabled. It might be a problem that in Actor section “Auto Receive Input” is Disabled. I also tried the value of 0 to match it with my BP’s.

Hi,

Doesn’t Transform from Bone Space in
Event Graph and “Transform (Modify)
Bone” in AnimGraph will do double
rotation?

No,
That node is converting a bone transform (+ input pins params if given) to world space coordinates.

We do that because we retrieve the camera location in world space so we need to keep consistent data for rotation computations.
That said I forgot to mention that you need to unlock Bone transform updates in Modify Bone Node within the AnimGraph in order to updates the bones transforms…

Rotation Mode to Replace and Rotation Space to world space to match the computations in the event graph…

In Event Graph there are “Get Player
Character” and “Get Player Camera
Manager” nodes with both Player Index
value of 0. Isn’t it supposed to be
the player? Aren’t we supposed to make
one of them the mesh we want to rotate
it as target to “Transform from Bone
Space”?

Well, at this point I want to say that it’s better that you create a Class Blueprint for the main character logic you want to implement and an AnimationBlueprint for…Animation/Bone management.

From your screenshots I can see that basically, you drag the animblueprint in the level while it’s better to drag a Class blueprint for which it’s skeletal mesh component is defined to be controlled by another AnimationBlueprint.

This is by far better because:

  1. You may want to reuse the logic you write for a component. This is more complicated to manage if you put all the component logic in a LevelBlueprint. Now I understand better why you’ve put the logic in the Level blueprint, basically to have access to the mesh instance you dragged in the level because it seems tricky to get it’s referenced skeletal mesh in the AnimBlueprint when you only have the latter used in the scene…
  2. Using a Class Blueprint let you add a lot of different components attached to your main one. The main mesh of course but also, for example, you can attach sounds, sensing component, trigger boxes and so on…and you have access to them automatically in all graphs of the blueprint. Then in the AnimBlueprint linked, to get the class bp ref, you only need a simple cast while you initialize it and you’ll see your class blueprint showing in the list of cast automatically…

I’ve tried in my project by dragging the turret anim bp into the scene and while I can get a few references like the controller and things like that, I cannot get a reference of the (skinned/skeletal) mesh in the event graph…
Maybe it’s possible but at this point and for the reasons I’ve wrote above, it’s definitely better to have

  1. One Class blueprint for the main logic of your component
  2. When apply, an animation Blueprint (that you specify being used in the animation section of your mesh class blueprint) to control all animation aspects of your skeletal mesh.

In the class blueprint I control all aspects related to sensing ennemies, triggering sounds, spawning bullets and particles…etc in an Event driven (custom event is nice :slight_smile:
In the animation blueprint, I manage the state machine and events related to turret animation…Perhaps, depending animation states, triggering in AnimBP the custom events defined in the Class BP…

Courage! :wink:

Hey,
I didn’t know it was that technical, sounded so easy at first =)

Okay, I did a Class Blueprint (Character) and attached my Mesh and Animation BP in Class Blueprint as Components. So far no log errors!

In my Class Blueprint:

  • I have the nodes I used in AnimBP’s Event Graph except for update animation and Delta Time, which caused problems. Which nodes should I replace them with?
  • Surely it didn’t recognize the Set Rot Value variable, and I created one for it. But it doesn’t apply for anim BP’s Get Rot Value, right? I was looking for “Cast To” function to cast set to my Animation BP, yet no outputs are correct for RotValue.

In my Anim Blueprint:

  • I have removed the shoulder joint rotation to simplify the workflow for now.
  • When I change the Yaw value of Transfrom Bone, it started to rotate finally! But it gets a default -90 value of Pitch. I tried BMM Additive and World Space and it fixed the problem and character is looking as it should, just FYI if it might be a problem.

So far no camera-related joint rotation. But it is probably the Rot Value is not transferred even I used ClassBP in my scene with AnimBP attached to it. I am reading carefully what you said and checking out documentation at the same time, yet I can’t fix it. I am starting to lose my hope :smiley:

Again, thank you so much for your help, even if I can’t do it so far I learned much!

Hi, it’s starting to work :slight_smile:

  • can you get a reference to your class blueprint from your anim one?

What’s the name of your Class Blueprint?

Edit: Sorry, my bad :slight_smile: I added a new variable and as Variable Type I made it “BP_Raynor” which is my anim blueprint right now

Class Blueprint: BP_Class_Raynor
Anim Blueprint: BP_Raynor

I have created the BP_Class_Raynor variable inside AnimBP and added InıtAnim and TryGetPawnOwner to Event Graph but didn’t understand how can I do that part:

try to get this ref by using TryGetPawnOwner to see if you can cast to your class bp

I am sorry if I am making nonsense questions :confused:

you should then be able to create a variable in your anim blueprint which is of type BP_Class_Raynor. In you anim bp event init animation, try to get this ref by using TryGetPawnOwner to see if you can cast to your class bp.

Hello Excalith.

I was in hope for finding a solution to make a bone rotate towards my character and I am successful after a few days of work. Do you still need help? If so I can share everything.

Regards.

Hello Achilleon,
Unfortunately I couldn’t manage to solve how to do it, I’d be grateful if you can share how you did this.

Thanks so much!

Sorry for late reply. Give me your skype and I will be glad to share the stuff and explain.

Or you can add “achilleon.” dot included and witout “”.

Hi Achilleon, sorry I missed the notification for your reply. I have postponed that project to work on later, now I have a better understanding of BP communications, I hope I will fix it in the future :slight_smile: I will add you now, maybe we can talk later! Thanks so much