I'm not sure how to phrase this question but here goes. What's the best way to make directional sprites for a Doom clone/2.5D shooter/whatever? I'm using the animation editor and not animation coordinates as in Miziziz's tutorials, as they didn't work correctly when I tried it - they rotated correctly, but the animation wouldn't play. I'm assuming that I need to get the dot product for z and y vectors, and convert (for lack of a better word) them into a string to determine which animation to play. How do I go about this? Am I completely missing something?

If this is in the wrong place, I apologize. My code since it's functionally identical to Miziziz's as of right now (except for the sprite coordinate part, obviously). His directional sprite code is here: https://pastebin.com/NxwySFsD (enemy) and https://pastebin.com/gDHUmJGq (camera).

24 days later

I'm no expert in 3D, but here's my 2 cents. First of all, I think the orientation of the camera shouldn't matter but the relative position of camera - even if a sprite comes towards you from your left side, it should show a forward sprite, not right sprite. Second thing I'd do is making this problem 2D by leaving y axis out of the equation.

Something like this (untested, sorry if it doesn't work as expected!):

var pos_2d = Vector2(global_transform.origin.x, global_transform.origin.z)
var camera_pos_2d = Vector2(camera.global_transform.origin.x, camera.global_transform.origin.z)
var camera_pos_2d_local = pos_2d - camera_pos_2d
var forward = global_transform.basis.z
var forward_2d = Vector2(forward.x, forward.z)
var angle = forward_2d.angle_to(camera_pos_2d_local)

Use this angle to determine actual sprite. Close to 0 should be forward, around PI backwards.

@aXu_AP said:> Something like this (untested, sorry if it doesn't work as expected!):

var pos_2d = Vector2(global_transform.origin.x, global_transform.origin.z)
var camera_pos_2d = Vector2(camera.global_transform.origin.x, camera.global_transform.origin.z)
var camera_pos_2d_local = pos_2d - camera_pos_2d
var forward = global_transform.basis.z
var forward_2d = Vector2(forward.x, forward.z)
var angle = forward_2d.angle_to(camera_pos_2d_local)

Use this angle to determine actual sprite. Close to 0 should be forward, around PI backwards.

Thank you so much for answering! Actually I haven't worked on this in a few weeks, could you elaborate a little more? Does that code go in the enemy or the player script?

Googled it but still a little unclear. What exactly is a directional sprite? @WildWoodsmith Do you mean a 2D sprite that's always facing the camera? If so that sounds like a billboard effect

@Erich_L said: Googled it but still a little unclear. What exactly is a directional sprite? @WildWoodsmith Do you mean a 2D sprite that's always facing the camera? If so that sounds like a billboard effect

It is a billboard effect, but it's a multi-directional billboard, for lack of a better term. Say, if the player's camera is looking at the enemy from an angle rather than head on, the enemy sprite will use it's "right-front" diagonal animation. If the player manages to get behind the enemy, the enemy sprite plays it's "rear" animation, etc.

I actually got this particular script to work https://pastebin.com/sUGHnvyk (used get_node() for the camera, and made some "placeholder" sprites) but I'm still unclear as to how I'd use it in actual gameplay, with things moving around and trying to kill the player and such.

@WildWoodsmith said: Thank you so much for answering! Actually I haven't worked on this in a few weeks, could you elaborate a little more? Does that code go in the enemy or the player script? Sorry for not elaborating, it should be in Sprite3D's script. Anyway, good to hear you got it to work :smile:

@Megalomaniak said: Imposter

Hmmm. I've heard of that. It bears looking into.

@aXu_AP Haven't tried your solution yet, unfortunately, but that's my next step - I think you're on the right track. However, I did get it to more or less function with some gameplay. The animation changes based on what direction the camera is facing, but I think I have the dot products mixed up (is there a guide or something that shows what direction is what? I can't find one). However, when the player shoots the zombie/enemy/whatever, it stops, but the walk animation keeps playing and the "die" animation never does.
I think my main problem is that I'm trying to take two different tutorials and mash them together.

https://pastebin.com/FvYn5HUC

a year later