Have widget look at camera using 'Find Look at Rotation'

Hi,
I’m trying to get a widget over the head of my character containing a health bar and a name to be constantly rotated, so that it looks like its always facing the camera:

http://puu.sh/icBsf/5df237ef5c.jpg

Since it’s supposed to be horizontal all the , the only thing that remains is the angle, that change is the character moves away or comes closer. I’ve tried setting up some stuff following [this][2] tutorial, but I have one problem: Since the guy in the tutorial has the widget face the character, rather then the camera I don’t know, how to get the location of the camera. Furthermore, I dont use ‘predefined’ cameras, but I spawn a camera actor at the start of the game and then blend to it right away:

http://puu.sh/icC3j/ae3797c736.png

How do I solve this?

This is what you would do on the level blueprint, check it out.

You don’t need to access the level bp from your character, just send the camera to a variable in your character bp via the level bp.

Here is how I set things up: I come into the level, spawn a camera actor and a pawn, blend to the camera and possess the pawn. The pawn has the widget as a component. Now here is the actual problem: I actually tried promoting the return value from the spawnActor node into a variable, but the problem is, I don’t know how to access the level blueprint from another blueprint thru casting or any means at all. Thats why i stored that variable in my gameInstance as a workaround, but i when i use that variable it stays static aka it doesnt work…

That seems, like it would be working, but here is the next problem: Before i come into my map i have the player choose his character from an array of characters and then spawn the chosen character in the main map:

http://puu.sh/id9Am/c4c41e763d.jpg

Now, how do i ‘dynamically’ cast to the correct character blueprint? I’ve seen a workaround, where you try all possible casts and on cast fail, you try the next one like: cast to char1 → fail → cast to char2… But i think that option is not viable, because in the final game 10 players will choose their characters and if i want to cast to char6, but someone chose char2, that cast wouldnt fail, thus giving the camera to the wrong player, right?

Generally when I run into a situation where I don’t know the class I will be needing to cast to, I would use a Blueprint interface and carry the information across in an interface function instead. BP interface functions don’t require casting and just work on any blueprint that is using the interface.

However in this case, it would simplify things considerably if you just have a camera component inside each character and use that camera when you possess the character.

Hmm, ok. Well if you don’t want to or can’t use a bp interface, another possible solution is to have the characters themselves spawn a camera actor and then posses that camera. Then the character BP would already have the return value reference inside.

I’ve been thinking about cameras as components as well, but I’ve implemented a RTS-style camera, which moves, when you hit the screen edges. However I haven’t been abel to get that to work with components, only with camera actors…

Actually I’ve thought of another solution that’s even simpler. You can use a Get All Actors of Class node. That will give you an array with all the camera actors in the scene. Assuming it’s the only camera actor in the scene, simply get index 1 (or possibly 0) from that array and there it is. =)

If I understand you correctly, this is what you mean?

http://puu.sh/idvHB/0eff51edde.jpg

Unfortunately, the angle still doesnt adjust :frowning:

http://puu.sh/idvMj/b0c5028d0d.jpg

http://puu.sh/idvND/167050b5fe.jpg

The idea is quite good though!

Try Index 1 and print the name of the actor to make sure you are getting the correct one.

I checked the world outliner while playing the game, it shows only 2 camera actors, whether i choose 0 or 1 as index, nothing changes…

Print the name of the actor and vector so you can see what’s actually happening.

You can use a Get All Actors of Class node. That will give you an array with all the camera actors in the scene. Assuming it’s the only camera actor in the scene, simply get index 1 (or possibly 0) from that array and there it is. =)

I was able to confirm the camera I’m looking through was the index 1. Final problem is, it doesn’t matter how i hook the rotation up, it doesnt change the angle.

http://puu.sh/ieoAN/873c49171a.jpg

Btw, why are all the previous comments gone?

EDIT: In one of your comments you mentioned i should print the vector of something, so i printed the rotation i get from ‘Find Look At Rotation’ and the actor location of the camera:

http://puu.sh/iet9c/bcc000b70a.jpg

However, as you can see the roll value is close to 0. I tried entering a value manually in the widget itself and found 60° to be a quite good, but obviously not perfect, value for roll:

http://puu.sh/ietgj/e0a3d80704.jpg

You should be trying to infuence the pitch and yaw not the roll. Check to make sure your widget component is facing the same direction your character is by default. Also I see in your first screenshot that the break rotation from the “look at rotation” isn’t connected to the Make Rotation, so double check that.

I actually want to influence the roll, because I want the widget to stay horizontal at all times. Basically I want a health bar like in DotA, or any RTS pretty much. The only problem is the angle as shown in the following picture isnt adjusting:

http://puu.sh/ii4fb/8f43b52928.png

Yes, I know. That’s not roll, that’s pitch. Change the roll of your character and you’ll see that he moves as if he’s doing a cartwheel. That’s not what you want.

If roll is doing what you want, then that means the orientation of the pivot/component is incorrect.

Also make sure the rotation of the widget is set to absolute/world, not relative.

HI

Pixel is right, think of roll in a boat. Side to side. Think of a Pitch, like a Baseball pitcher, ball going forward but will go up and down.

The like below might help, only 5 mins and works to a T

I made a screenshot for you guys, so you can see, that I actually need the roll and that nothing is rotated so far:

http://puu.sh/iiFjl/4eb6b8a687.jpg

Again, for the camera, its suppose to look like a 2D floating over the characters head, not changing its scale, rotation or angle when viewed from the cameras perspective (which is the whole game).

Your explanation is perfectly logical, , but it just doesnt work out for me… By the way, I was following this exact tutorial, but you see the resluts so far :confused:

Like I said, that means your widget (and it looks like your character as well) are facing the wrong way. Look at that blue arrow component. Your other components should be facing that direction as well.

Also, try setting the widget rotation to world/absolute rotation. It looks like It’s currently set to relative.