Figured out clean WIP look at/move towards action
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
extends Node3D
|
||||
|
||||
|
||||
@onready var player: Node3D = $player
|
||||
@onready var target: MeshInstance3D = $target
|
||||
@onready var camera: Camera3D = $player/camera
|
||||
@onready var ray: RayCast3D = $player/ray
|
||||
@onready var dir_vec: RayCast3D = $dir_vec
|
||||
|
||||
var WIDTH: int = 960 # (1920/2)
|
||||
var HEIGHT: int = 540 # (1080/2)
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
var difference_vector: Vector3 = player.to_local(target.global_position)
|
||||
var direction_vector: Vector3 = difference_vector.normalized()
|
||||
|
||||
ray.target_position = direction_vector
|
||||
dir_vec.target_position = direction_vector
|
||||
# NOTE: Divide by 2 and +- that for same range but center of 'screen' is 0,0.
|
||||
# Otherwise, 0,0 is top left
|
||||
var pixil_x = direction_vector.x * WIDTH
|
||||
var pixil_y = direction_vector.y * HEIGHT
|
||||
print("X: ", pixil_x)
|
||||
print("Y: ", pixil_y)
|
||||
Reference in New Issue
Block a user