add aiming with controller
This commit is contained in:
parent
25f334ba26
commit
86e59dce55
@ -58,6 +58,11 @@ import/blender/enabled=false
|
|||||||
|
|
||||||
[input]
|
[input]
|
||||||
|
|
||||||
|
toggle_debug={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":96,"key_label":0,"unicode":96,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
move_up={
|
move_up={
|
||||||
"deadzone": 0.5,
|
"deadzone": 0.5,
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"location":0,"echo":false,"script":null)
|
||||||
@ -82,9 +87,24 @@ move_right={
|
|||||||
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
|
, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":0,"axis_value":1.0,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
toggle_debug={
|
aim_up={
|
||||||
"deadzone": 0.5,
|
"deadzone": 0.5,
|
||||||
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":96,"key_label":0,"unicode":96,"location":0,"echo":false,"script":null)
|
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
aim_down={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
aim_left={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
aim_right={
|
||||||
|
"deadzone": 0.5,
|
||||||
|
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":1.0,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -31,3 +31,5 @@ func _follow() -> void:
|
|||||||
global_position = (
|
global_position = (
|
||||||
follow_position + Vector3.UP * height_offset + transform.basis.z * distance
|
follow_position + Vector3.UP * height_offset + transform.basis.z * distance
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Debugger.circle("follow_position", follow_position)
|
||||||
|
|||||||
@ -9,11 +9,14 @@ const FALL_SPEED: float = 20
|
|||||||
const FALL_ACCELERATION: float = 25
|
const FALL_ACCELERATION: float = 25
|
||||||
|
|
||||||
@export var _respawn_height: float = -5
|
@export var _respawn_height: float = -5
|
||||||
|
@export var _aim_mult_x: float = 20
|
||||||
|
@export var _aim_mult_y: float = 27
|
||||||
|
|
||||||
var aim_offset: Vector3
|
var aim_offset: Vector3
|
||||||
|
|
||||||
var _respawn_point: Vector3
|
var _respawn_point: Vector3
|
||||||
var _floor_height: float = 0
|
var _floor_height: float = 0
|
||||||
|
var _move_input: Vector2
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
@ -22,9 +25,12 @@ func _ready() -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _process(_delta: float) -> void:
|
func _process(_delta: float) -> void:
|
||||||
|
_controller_aiming()
|
||||||
call_deferred("_mouse_aiming")
|
call_deferred("_mouse_aiming")
|
||||||
_process_respawning()
|
_process_respawning()
|
||||||
|
|
||||||
|
Debugger.marker("aim", global_position + aim_offset)
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta: float) -> void:
|
func _physics_process(delta: float) -> void:
|
||||||
if not is_multiplayer_authority():
|
if not is_multiplayer_authority():
|
||||||
@ -36,23 +42,52 @@ func _physics_process(delta: float) -> void:
|
|||||||
move_and_slide()
|
move_and_slide()
|
||||||
|
|
||||||
|
|
||||||
|
func _controller_aiming() -> void:
|
||||||
|
if Inputer.mode != Inputer.Mode.CONTROLLER:
|
||||||
|
return
|
||||||
|
|
||||||
|
var aim_input := Input.get_vector("aim_left", "aim_right", "aim_up", "aim_down")
|
||||||
|
|
||||||
|
if aim_input.length() == 0:
|
||||||
|
return
|
||||||
|
|
||||||
|
var aim_input_norm := aim_input.normalized()
|
||||||
|
|
||||||
|
aim_offset = (
|
||||||
|
Vector3(aim_input_norm.x * _aim_mult_x, 0, aim_input_norm.y * _aim_mult_y)
|
||||||
|
. rotated(Vector3.UP, Referencer.main_camera.rotation.y)
|
||||||
|
)
|
||||||
|
|
||||||
|
look_at(global_position + aim_offset, Vector3.UP, true)
|
||||||
|
|
||||||
|
|
||||||
func _mouse_aiming() -> void:
|
func _mouse_aiming() -> void:
|
||||||
|
if Inputer.mode != Inputer.Mode.KB_MOUSE:
|
||||||
|
return
|
||||||
|
|
||||||
var player_position := global_position
|
var player_position := global_position
|
||||||
if is_on_floor():
|
if is_on_floor():
|
||||||
_floor_height = player_position.y
|
_floor_height = player_position.y
|
||||||
player_position.y = _floor_height
|
player_position.y = _floor_height
|
||||||
|
|
||||||
var aim_position := _mouse_project(_floor_height)
|
var aim_position := _mouse_project(_floor_height)
|
||||||
aim_offset = aim_position - player_position
|
aim_offset = aim_position - player_position
|
||||||
aim_position.y = global_position.y
|
aim_position.y = global_position.y
|
||||||
|
|
||||||
|
if aim_position == global_position:
|
||||||
|
return
|
||||||
|
|
||||||
look_at(aim_position, Vector3.UP, true)
|
look_at(aim_position, Vector3.UP, true)
|
||||||
|
|
||||||
|
|
||||||
func _mouse_project(height: float) -> Vector3:
|
func _mouse_project(height: float) -> Vector3:
|
||||||
var mouse_pos := get_viewport().get_mouse_position()
|
var mouse_pos := get_viewport().get_mouse_position()
|
||||||
var camera := Referencer.main_camera
|
var camera := Referencer.main_camera
|
||||||
|
|
||||||
var from := camera.project_ray_origin(mouse_pos)
|
var from := camera.project_ray_origin(mouse_pos)
|
||||||
var direction := camera.project_ray_normal(mouse_pos)
|
var direction := camera.project_ray_normal(mouse_pos)
|
||||||
var plane := Plane(Vector3.UP, height)
|
var plane := Plane(Vector3.UP, height)
|
||||||
|
|
||||||
var intersection: Variant = plane.intersects_ray(from, direction)
|
var intersection: Variant = plane.intersects_ray(from, direction)
|
||||||
if not intersection:
|
if not intersection:
|
||||||
return Vector3.ZERO
|
return Vector3.ZERO
|
||||||
@ -66,11 +101,10 @@ func _process_respawning() -> void:
|
|||||||
|
|
||||||
|
|
||||||
func _lateral_movement(delta: float) -> void:
|
func _lateral_movement(delta: float) -> void:
|
||||||
var input_dir := Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
_move_input = Input.get_vector("move_left", "move_right", "move_up", "move_down")
|
||||||
var has_input := input_dir.length() > 0
|
|
||||||
|
|
||||||
if has_input:
|
if _move_input.length() > 0:
|
||||||
var direction := Vector3(input_dir.x, 0, input_dir.y).normalized()
|
var direction := Vector3(_move_input.x, 0, _move_input.y).normalized()
|
||||||
var new_velocity := (direction * MOVE_SPEED).rotated(
|
var new_velocity := (direction * MOVE_SPEED).rotated(
|
||||||
Vector3.UP, Referencer.main_camera.rotation.y
|
Vector3.UP, Referencer.main_camera.rotation.y
|
||||||
)
|
)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user