first examples
This commit is contained in:
parent
a01a7a7acc
commit
2219e943da
33 changed files with 785 additions and 6 deletions
52
entities/viewer/viewer.gd
Normal file
52
entities/viewer/viewer.gd
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
extends CharacterBody3D
|
||||
|
||||
@export var rotation_speed: float = 0.002
|
||||
|
||||
|
||||
const SPEED = 5.0
|
||||
const JUMP_VELOCITY = 4.5
|
||||
|
||||
func _ready() -> void:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if Input.is_action_pressed("ui_cancel"):
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
|
||||
if event is InputEventMouseButton and event.button_index == 1 and event.is_pressed():
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
|
||||
if event is InputEventMouseMotion:
|
||||
handle_motion(event)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Add the gravity.
|
||||
if not is_on_floor():
|
||||
velocity += get_gravity() * delta
|
||||
|
||||
# Handle jump.
|
||||
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
|
||||
velocity.y = JUMP_VELOCITY
|
||||
|
||||
# Get the input direction and handle the movement/deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
var input_dir := Input.get_vector("left", "right", "front", "back")
|
||||
var direction := (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
||||
if direction:
|
||||
velocity.x = direction.x * SPEED
|
||||
velocity.z = direction.z * SPEED
|
||||
else:
|
||||
velocity.x = move_toward(velocity.x, 0, SPEED)
|
||||
velocity.z = move_toward(velocity.z, 0, SPEED)
|
||||
|
||||
move_and_slide()
|
||||
|
||||
func handle_motion(event: InputEventMouseMotion) -> void:
|
||||
if not Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
||||
return
|
||||
|
||||
$Camera3D.rotation.x -= event.relative.y * rotation_speed
|
||||
$Camera3D.rotation.x = clamp($Camera3D.rotation.x, deg_to_rad(-89), deg_to_rad(89))
|
||||
rotation.y -= event.relative.x * rotation_speed
|
||||
17
entities/viewer/viewer.tscn
Normal file
17
entities/viewer/viewer.tscn
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://dcv8xw0aeturp"]
|
||||
|
||||
[ext_resource type="Script" path="res://entities/viewer/viewer.gd" id="1_8hs0o"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_bf5le"]
|
||||
height = 1.7
|
||||
|
||||
[node name="Viewer" type="CharacterBody3D"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 5)
|
||||
script = ExtResource("1_8hs0o")
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.7, 0)
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.85, 0)
|
||||
shape = SubResource("CapsuleShape3D_bf5le")
|
||||
Loading…
Add table
Add a link
Reference in a new issue