Directional sprite now should kinda work
This commit is contained in:
parent
39fb87f62d
commit
45e56e86d1
1 changed files with 4 additions and 3 deletions
|
@ -8,10 +8,11 @@ func _process(delta: float) -> void:
|
||||||
var camera = get_viewport().get_camera_3d()
|
var camera = get_viewport().get_camera_3d()
|
||||||
if Engine.is_editor_hint():
|
if Engine.is_editor_hint():
|
||||||
camera = EditorInterface.get_editor_viewport_3d().get_camera_3d()
|
camera = EditorInterface.get_editor_viewport_3d().get_camera_3d()
|
||||||
var rotation_to_camera = -vec3_to_vec2(global_transform.basis.z).angle_to(vec3_to_vec2(camera.global_position)) + PI
|
# Angle between camera's -basis.z (forward direction) and direction to camera
|
||||||
|
var angle = vec3_to_vec2(-global_transform.basis.z).angle_to(vec3_to_vec2(global_position - camera.global_position)) + PI
|
||||||
var chosen_index = 0
|
var chosen_index = 0
|
||||||
for i in rotations.keys():
|
for i in rotations.keys():
|
||||||
if abs(rotation_to_camera-i) < abs(rotation_to_camera-chosen_index):
|
if abs(angle-i) < abs(angle-chosen_index):
|
||||||
chosen_index = i
|
chosen_index = i
|
||||||
texture = rotations[chosen_index]
|
texture = rotations[chosen_index]
|
||||||
|
|
||||||
|
@ -24,4 +25,4 @@ func entry_generator():
|
||||||
rotations[TAU/rotation_count*i] = Texture2D.new()
|
rotations[TAU/rotation_count*i] = Texture2D.new()
|
||||||
|
|
||||||
func vec3_to_vec2(vector : Vector3) -> Vector2:
|
func vec3_to_vec2(vector : Vector3) -> Vector2:
|
||||||
return Vector2(vector.x,vector.z).normalized()
|
return Vector2(vector.z,vector.x).normalized()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue