Unity and Cocos stay as parallel schemes; apps/minigame ships the Godot 4.7 WeChat pack for DevTools. Co-authored-by: Cursor <cursoragent@cursor.com>
69 lines
1.9 KiB
GDScript
69 lines
1.9 KiB
GDScript
extends CharacterBody3D
|
|
|
|
@export var speed := 7.2
|
|
@export var look_sensitivity := 0.0038
|
|
|
|
var _cam: Camera3D
|
|
var _joy := Vector2.ZERO
|
|
var _visual: Node3D
|
|
|
|
func _ready() -> void:
|
|
_cam = $CameraPivot/Camera3D
|
|
collision_layer = 1
|
|
collision_mask = 1
|
|
add_to_group("player")
|
|
if has_node("Body"):
|
|
$Body.visible = false
|
|
_visual = AvatarFactory.build("player", Color("F59E0B"), Color("FFCCBC"))
|
|
add_child(_visual)
|
|
|
|
func set_joystick(v: Vector2) -> void:
|
|
_joy = v
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
var input := Vector2(
|
|
Input.get_axis("move_left", "move_right"),
|
|
Input.get_axis("move_forward", "move_back")
|
|
)
|
|
if _joy.length() > 0.05:
|
|
input = _joy
|
|
var basis_flat := global_transform.basis
|
|
var forward := -basis_flat.z
|
|
forward.y = 0.0
|
|
forward = forward.normalized()
|
|
var right := basis_flat.x
|
|
right.y = 0.0
|
|
right = right.normalized()
|
|
var dir := (right * input.x + forward * input.y)
|
|
if dir.length() > 0.001:
|
|
dir = dir.normalized()
|
|
velocity.x = dir.x * speed
|
|
velocity.z = dir.z * speed
|
|
if _visual:
|
|
var look := atan2(dir.x, dir.z)
|
|
_visual.rotation.y = lerp_angle(_visual.rotation.y, look - rotation.y, 1.0 - exp(-12.0 * delta))
|
|
if _visual.has_method("set_moving"):
|
|
_visual.set_moving(true)
|
|
else:
|
|
velocity.x = move_toward(velocity.x, 0.0, speed * 16.0 * delta)
|
|
velocity.z = move_toward(velocity.z, 0.0, speed * 16.0 * delta)
|
|
if _visual and _visual.has_method("set_moving"):
|
|
_visual.set_moving(false)
|
|
if not is_on_floor():
|
|
velocity.y -= 18.0 * delta
|
|
else:
|
|
velocity.y = -0.5
|
|
move_and_slide()
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
if event is InputEventScreenDrag:
|
|
var drag := event as InputEventScreenDrag
|
|
if drag.position.x > get_viewport().get_visible_rect().size.x * 0.42:
|
|
rotate_y(-drag.relative.x * look_sensitivity)
|
|
if _cam:
|
|
_cam.rotation.x = clamp(
|
|
_cam.rotation.x - drag.relative.y * look_sensitivity,
|
|
deg_to_rad(-28.0),
|
|
deg_to_rad(18.0)
|
|
)
|