refactor mouse aiming
This commit is contained in:
parent
94cba32857
commit
df37371fad
@ -16,7 +16,6 @@ run/main_scene="res://scenes/test.tscn"
|
||||
config/use_custom_user_dir=true
|
||||
config/custom_user_dir_name="Batrix"
|
||||
config/features=PackedStringArray("4.3", "Forward Plus")
|
||||
run/max_fps=60
|
||||
boot_splash/bg_color=Color(0, 0, 0, 1)
|
||||
boot_splash/show_image=false
|
||||
config/icon="res://icon.svg"
|
||||
|
||||
@ -23,7 +23,6 @@ func _ready() -> void:
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
call_deferred("_mouse_aiming")
|
||||
|
||||
_process_respawning()
|
||||
|
||||
|
||||
@ -37,31 +36,29 @@ func _physics_process(delta: float) -> void:
|
||||
move_and_slide()
|
||||
|
||||
|
||||
func _mouse_project(
|
||||
mouse_pos: Vector2, player_pos: Vector3, camera: Camera3D
|
||||
) -> Vector3:
|
||||
var from := camera.project_ray_origin(mouse_pos)
|
||||
var direction := camera.project_ray_normal(mouse_pos)
|
||||
var plane := Plane(Vector3.UP, player_pos)
|
||||
var intersection: Variant = plane.intersects_ray(from, direction)
|
||||
if not intersection:
|
||||
return Vector3.ZERO
|
||||
return intersection as Vector3
|
||||
|
||||
|
||||
func _mouse_aiming() -> void:
|
||||
var mouse_pos := get_viewport().get_mouse_position()
|
||||
var player_position := global_position
|
||||
if is_on_floor():
|
||||
_floor_height = player_position.y
|
||||
player_position.y = _floor_height
|
||||
var camera := Referencer.main_camera
|
||||
var aim_position := _mouse_project(mouse_pos, player_position, camera)
|
||||
var aim_position := _mouse_project(_floor_height)
|
||||
aim_offset = aim_position - player_position
|
||||
aim_position.y = global_position.y
|
||||
look_at(aim_position, Vector3.UP, true)
|
||||
|
||||
|
||||
func _mouse_project(height: float) -> Vector3:
|
||||
var mouse_pos := get_viewport().get_mouse_position()
|
||||
var camera := Referencer.main_camera
|
||||
var from := camera.project_ray_origin(mouse_pos)
|
||||
var direction := camera.project_ray_normal(mouse_pos)
|
||||
var plane := Plane(Vector3.UP, height)
|
||||
var intersection: Variant = plane.intersects_ray(from, direction)
|
||||
if not intersection:
|
||||
return Vector3.ZERO
|
||||
return intersection as Vector3
|
||||
|
||||
|
||||
func _process_respawning() -> void:
|
||||
if global_position.y < _respawn_height:
|
||||
global_position = _respawn_point
|
||||
|
||||
Loading…
Reference in New Issue
Block a user