generated from krampus/template-godot4
Free camera
This commit is contained in:
parent
5b97c3f047
commit
cb176e1805
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=30 format=3 uid="uid://bm2o3mex10v11"]
|
||||
[gd_scene load_steps=31 format=3 uid="uid://bm2o3mex10v11"]
|
||||
|
||||
[ext_resource type="Terrain3DStorage" uid="uid://bu1gewgsgc5hm" path="res://levels/debug_level/terrain_3d_storage.res" id="1_nlsu2"]
|
||||
[ext_resource type="Texture2D" path="res://assets/textures/grass_fairway/grass_fairway_albedo.dds" id="2_e4m27"]
|
||||
|
@ -7,6 +7,7 @@
|
|||
[ext_resource type="Shader" path="res://src/shaders/toon_water.gdshader" id="5_meq7l"]
|
||||
[ext_resource type="Shader" path="res://src/shaders/psx_water.gdshader" id="6_0efu4"]
|
||||
[ext_resource type="Texture2D" uid="uid://con5a36t6n6sq" path="res://assets/textures/clear_sea_water_2048x2048.png" id="7_t86h2"]
|
||||
[ext_resource type="PackedScene" uid="uid://dd17ce110sw6p" path="res://src/player/game_camera.tscn" id="8_kum8r"]
|
||||
|
||||
[sub_resource type="FastNoiseLite" id="FastNoiseLite_rpgb7"]
|
||||
noise_type = 0
|
||||
|
@ -97,6 +98,10 @@ sky_material = SubResource("PanoramaSkyMaterial_h8tes")
|
|||
background_mode = 2
|
||||
sky = SubResource("Sky_68xob")
|
||||
ambient_light_source = 2
|
||||
volumetric_fog_enabled = true
|
||||
volumetric_fog_density = 0.005
|
||||
volumetric_fog_emission = Color(0, 1, 1, 1)
|
||||
volumetric_fog_length = 32.0
|
||||
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_dk53r"]
|
||||
|
||||
|
@ -175,9 +180,6 @@ transform = Transform3D(1, 0, 0, 0, -0.149535, 0.988756, 0, -0.988756, -0.149535
|
|||
transform = Transform3D(-0.480912, 0, -0.876769, 0, 1, 0, 0.876769, 0, -0.480912, 222.404, 5, 265.619)
|
||||
mesh = SubResource("CapsuleMesh_dk53r")
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="Player"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
||||
|
||||
[node name="WaterTable" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0)
|
||||
visible = false
|
||||
|
@ -186,3 +188,6 @@ mesh = SubResource("PlaneMesh_4pasq")
|
|||
[node name="WaterTable2" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -2, 0)
|
||||
mesh = SubResource("PlaneMesh_2ywhk")
|
||||
|
||||
[node name="GameCamera" parent="." instance=ExtResource("8_kum8r")]
|
||||
transform = Transform3D(-0.666804, 0.0966855, -0.738935, 0, 0.991548, 0.129739, 0.745233, 0.0865102, -0.661168, 215.296, 6.58096, 262.213)
|
||||
|
|
|
@ -42,9 +42,58 @@ movie_writer/movie_file="demos/demo.avi"
|
|||
|
||||
enabled=PackedStringArray("res://addons/format_on_save/plugin.cfg", "res://addons/gdlint_plugin/plugin.cfg", "res://addons/terrain_3d/plugin.cfg")
|
||||
|
||||
[game]
|
||||
|
||||
config/controls/camera/free_camera_speed=10.0
|
||||
config/controls/camera/x_axis_sensitivity=0.45
|
||||
config/controls/camera/y_axis_sensitivity=0.45
|
||||
config/controls/camera/x_axis_acceleration=30.0
|
||||
config/controls/camera/y_axis_acceleration=30.0
|
||||
config/controls/camera/invert_pitch=false
|
||||
|
||||
[input]
|
||||
|
||||
camera_forward={
|
||||
"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,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
camera_back={
|
||||
"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":83,"key_label":0,"unicode":115,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
camera_left={
|
||||
"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":65,"key_label":0,"unicode":97,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
camera_right={
|
||||
"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":68,"key_label":0,"unicode":100,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
camera_up={
|
||||
"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":32,"key_label":0,"unicode":32,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
camera_down={
|
||||
"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":4194326,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
camera_sprint={
|
||||
"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":4194325,"key_label":0,"unicode":0,"echo":false,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[layer_names]
|
||||
|
||||
3d_physics/layer_1="Collision Geometry"
|
||||
|
||||
[rendering]
|
||||
|
||||
textures/canvas_textures/default_texture_filter=0
|
||||
anti_aliasing/quality/msaa_3d=3
|
||||
anti_aliasing/quality/use_taa=true
|
||||
anti_aliasing/quality/use_debanding=true
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
class_name GameCamera extends CharacterBody3D
|
||||
|
||||
const SPRINT_MULT := 2.0
|
||||
const PITCH_MAX := deg_to_rad(85.0)
|
||||
|
||||
var base_speed: float = ProjectSettings.get_setting("game/config/controls/camera/free_camera_speed")
|
||||
|
||||
var x_sensitivity: float = ProjectSettings.get_setting(
|
||||
"game/config/controls/camera/x_axis_sensitivity"
|
||||
)
|
||||
var x_acceleration: float = ProjectSettings.get_setting(
|
||||
"game/config/controls/camera/x_axis_acceleration"
|
||||
)
|
||||
var y_sensitivity: float = ProjectSettings.get_setting(
|
||||
"game/config/controls/camera/y_axis_sensitivity"
|
||||
)
|
||||
var y_acceleration: float = ProjectSettings.get_setting(
|
||||
"game/config/controls/camera/y_axis_acceleration"
|
||||
)
|
||||
|
||||
var invert_pitch: bool = ProjectSettings.get_setting("game/config/controls/camera/invert_pitch")
|
||||
|
||||
@onready var _target := Vector2(rotation.x, rotation.y)
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventMouseButton:
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
elif event is InputEventMouseMotion:
|
||||
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
camera_motion((event as InputEventMouseMotion).relative)
|
||||
|
||||
|
||||
func camera_motion(motion: Vector2) -> void:
|
||||
_target.y = _target.y - deg_to_rad(motion.x * x_sensitivity)
|
||||
_target.x = clampf(
|
||||
_target.x - deg_to_rad(motion.y * y_sensitivity) * (-1 if invert_pitch else 1),
|
||||
-PITCH_MAX,
|
||||
PITCH_MAX,
|
||||
)
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
# Rotation
|
||||
rotation.y = lerp_angle(rotation.y, _target.y, delta * x_acceleration)
|
||||
rotation.x = lerp_angle(rotation.x, _target.x, delta * y_acceleration)
|
||||
|
||||
# Handle spatial movement
|
||||
var xz_input := Input.get_vector("camera_left", "camera_right", "camera_forward", "camera_back")
|
||||
var y_input := Input.get_vector("", "", "camera_down", "camera_up")
|
||||
var direction := (transform.basis * Vector3(xz_input.x, y_input.y, xz_input.y)).normalized()
|
||||
|
||||
var speed := base_speed
|
||||
if Input.is_action_pressed("camera_sprint"):
|
||||
speed *= SPRINT_MULT
|
||||
|
||||
if direction:
|
||||
velocity = direction * speed
|
||||
else:
|
||||
velocity = velocity.move_toward(Vector3.ZERO, speed)
|
||||
|
||||
move_and_slide()
|
|
@ -0,0 +1,13 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://dd17ce110sw6p"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/player/game_camera.gd" id="1_3gm3q"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_wmusx"]
|
||||
|
||||
[node name="GameCamera" type="CharacterBody3D"]
|
||||
script = ExtResource("1_3gm3q")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("SphereShape3D_wmusx")
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="."]
|
|
@ -0,0 +1,11 @@
|
|||
extends Node3D
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
|
@ -0,0 +1,6 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://cy7t2tc4y3b4"]
|
||||
|
||||
[ext_resource type="Script" path="res://src/player/shot_setup.gd" id="1_r6ei4"]
|
||||
|
||||
[node name="ShotSetup" type="Node3D"]
|
||||
script = ExtResource("1_r6ei4")
|
Loading…
Reference in New Issue