How to make a 3D sprite always look at the player?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By andrew012623

im new at godot, and I have tried to make a Sprite 3D always turn to see my first person player, but I can not do it correctly. I tried the billboard function but the Sprite looks strange because it does not remain static to the ground, I move the camera and the sprite lengthens or shrinks in order to see itself, and that’s not what I want, what I want is that only its “Y” rotation always change giving me the face, something similar to danganronpa so you can understand perfectly what I’m looking for. Maybe that can be solved with GDscript in the Sprite, but I have not managed to do it, do you know any effective way to do it? I have surrendered with the billboard function that is what everyone talks about and without much info, I can not find any tutorial that can do what I want, I would appreciate any help :frowning:

:bust_in_silhouette: Reply From: Zylann

The billboard function should not shrink or lengthen the sprite, it should just make it look at you.

If you want only the Y rotation to change, maybe this can do it:

func _process(delta):
	var camera_pos = get_viewport().get_camera().global_transform.origin
	camera_pos.y = 0
	look_at(camera_pos, Vector3(0, 1, 0))

I think there is a way using a custom shader but I don’t have the math in mind.

Edit: oh wait, there is an Y-billboard mode in SpatialMaterial… I tried it and it works well, why is this not suitable? Are you using Godot 2 or 3?

Ok i tried your code and i think we’re so much close, the only problem is that when im in front of the sprite this one inclines to me, and if i pass through him he gives a 360° turn in X axis, but dude thank you finally something works :smiley:

About Y-Billboard i tried that too and actually it works perfectly, the problem? i dont know why but the sprite turns fat, literally, its X-Scale grows and i cant change it even if i use the Scale Mode or if i manually decrease its X-Scale in Inspector menu, but the Y rotation works perfectly, using Godot 3. Now, being a SpatialMaterial, i put the Transparent, Unshaded and Albedo Tex For flags in order to make it visible and in good quality, im not sure if one of those flags makes the Y-billboard not suitable (pretty much sure its not that) or maybe my sprite was made wrongly (could be), or maybe is my version of godot, are you using godot 2?

andrew012623 | 2018-07-05 04:59

You know what? i think its my sprite, maybe it is wrong after all, im drawing a character in flash professional cc, and then i export it as a sprite sheet, i guess thats the problem, because after trying the Y-billboard with the godot icon worked well, so it seems that the real question is how can i make my flash drawing a sprite correctly? how do you make your sprites? any program in particular?

andrew012623 | 2018-07-05 10:28

Ugh, well any PNG or atlas should work normally. If an atlas causes problems then you probably hit a bug^^ Do you have an example project I can checkout?

Zylann | 2018-07-06 00:32

Hey buddy dont worry, i finally solved it! using Y-Billboard function, but thank you for all the help, i appreciate it, actually if you hadnt mentioned the billboard i wouldnt insist with it and i would be struggling. Thank you!!

andrew012623 | 2018-07-06 21:27

This worked wonderfully. Thanks.

animanoir | 2022-01-22 05:41

:bust_in_silhouette: Reply From: idbrii

To make the correct answer more obvious, here’s AlexTheRegent’s answer to a similar question:

You probably need to set Flags > Billboard to Y-Billboard at your Sprite3D node. This way, it should always face active camera, no matter how many of them you have.

These Flags work for Label3D too!