add player rotating towards the mouse
This commit is contained in:
@@ -19,6 +19,7 @@ func _ready() -> void:
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
_mouse_turning()
|
||||
_process_respawning()
|
||||
|
||||
|
||||
@@ -26,12 +27,25 @@ func _physics_process(delta: float) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
|
||||
_mouse_turning()
|
||||
_lateral_movement(delta)
|
||||
_vertical_movement(delta)
|
||||
|
||||
move_and_slide()
|
||||
|
||||
|
||||
func _mouse_turning() -> void:
|
||||
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, global_position)
|
||||
var intersection: Variant = plane.intersects_ray(from, direction)
|
||||
if not intersection:
|
||||
return
|
||||
look_at(intersection as Vector3, Vector3.UP, true)
|
||||
|
||||
|
||||
func _process_respawning() -> void:
|
||||
if global_position.y < _respawn_height:
|
||||
global_position = _respawn_point
|
||||
@@ -39,15 +53,11 @@ func _process_respawning() -> void:
|
||||
|
||||
|
||||
func _lateral_movement(delta: float) -> void:
|
||||
var input_dir := Input.get_vector(
|
||||
"move_left", "move_right", "move_up", "move_down"
|
||||
)
|
||||
var input_dir := Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||
var has_input := input_dir.length() > 0
|
||||
|
||||
if has_input:
|
||||
var direction := (
|
||||
(transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
)
|
||||
var direction := Vector3(input_dir.x, 0, input_dir.y).normalized()
|
||||
var new_velocity := (direction * MOVE_SPEED).rotated(
|
||||
Vector3.UP, Referencer.main_camera.rotation.y
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user