New reticle system
This commit is contained in:
@ -11,6 +11,7 @@ extends CharacterBody3D
|
||||
@export var jump_velocity : float = 4.5
|
||||
@export var mouse_sensitivity : float = 0.1
|
||||
@export var immobile : bool = false
|
||||
@export_file var default_reticle
|
||||
|
||||
@export var initial_facing_direction : Vector3 = Vector3.ZERO
|
||||
|
||||
@ -60,6 +61,8 @@ var state : String = "normal"
|
||||
var low_ceiling : bool = false # This is for when the cieling is too low and the player needs to crouch.
|
||||
var was_on_floor : bool = true
|
||||
|
||||
var RETICLE : Control
|
||||
|
||||
# Get the gravity from the project settings to be synced with RigidBody nodes
|
||||
var gravity : float = ProjectSettings.get_setting("physics/3d/default_gravity") # Don't set this as a const, see the gravity section in _physics_process
|
||||
|
||||
@ -71,12 +74,24 @@ func _ready():
|
||||
if initial_facing_direction:
|
||||
HEAD.set_rotation_degrees(initial_facing_direction) # I don't want to be calling this function if the vector is zero
|
||||
|
||||
if default_reticle:
|
||||
change_reticle(default_reticle)
|
||||
|
||||
# Reset the camera position
|
||||
HEADBOB_ANIMATION.play("RESET")
|
||||
JUMP_ANIMATION.play("RESET")
|
||||
CROUCH_ANIMATION.play("RESET")
|
||||
|
||||
|
||||
func change_reticle(reticle):
|
||||
if RETICLE:
|
||||
RETICLE.queue_free()
|
||||
|
||||
RETICLE = load(reticle).instantiate()
|
||||
RETICLE.character = self
|
||||
$UserInterface.add_child(RETICLE)
|
||||
|
||||
|
||||
func _physics_process(delta):
|
||||
current_speed = Vector3.ZERO.distance_to(get_real_velocity())
|
||||
$UserInterface/DebugPanel.add_property("Speed", snappedf(current_speed, 0.001), 1)
|
||||
|
@ -1,7 +1,6 @@
|
||||
[gd_scene load_steps=21 format=3 uid="uid://cc1m2a1obsyn4"]
|
||||
[gd_scene load_steps=20 format=3 uid="uid://cc1m2a1obsyn4"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/fpc/character.gd" id="1_0t4e8"]
|
||||
[ext_resource type="PackedScene" uid="uid://3mij3cjhkwsm" path="res://addons/fpc/reticles/reticle_1.tscn" id="2_uuexm"]
|
||||
[ext_resource type="Script" path="res://addons/fpc/debug.gd" id="3_x1wcc"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_kp17n"]
|
||||
@ -386,6 +385,7 @@ MarginContainer/constants/margin_top = 10
|
||||
|
||||
[node name="Character" type="CharacterBody3D" node_paths=PackedStringArray("HEAD", "CAMERA", "HEADBOB_ANIMATION", "JUMP_ANIMATION", "CROUCH_ANIMATION", "COLLISION_MESH")]
|
||||
script = ExtResource("1_0t4e8")
|
||||
default_reticle = "res://addons/fpc/reticles/reticle_1.tscn"
|
||||
HEAD = NodePath("Head")
|
||||
CAMERA = NodePath("Head/Camera")
|
||||
HEADBOB_ANIMATION = NodePath("Head/HeadbobAnimation")
|
||||
@ -435,11 +435,6 @@ grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
mouse_filter = 1
|
||||
|
||||
[node name="Reticle_1" parent="UserInterface" node_paths=PackedStringArray("reticle_lines", "character") instance=ExtResource("2_uuexm")]
|
||||
layout_mode = 1
|
||||
reticle_lines = [NodePath("top"), NodePath("left"), NodePath("right"), NodePath("bottom")]
|
||||
character = NodePath("../..")
|
||||
|
||||
[node name="DebugPanel" type="PanelContainer" parent="UserInterface"]
|
||||
visible = false
|
||||
layout_mode = 0
|
||||
@ -460,5 +455,3 @@ layout_mode = 2
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0)
|
||||
shape = SubResource("SphereShape3D_k4wwl")
|
||||
target_position = Vector3(0, 0.5, 0)
|
||||
|
||||
[editable path="UserInterface/Reticle_1"]
|
||||
|
@ -73,7 +73,7 @@ func update_reticle_settings():
|
||||
reticle_lines[3].points[1].y = line_length + line_distance
|
||||
"
|
||||
|
||||
[node name="Reticle" type="CenterContainer"]
|
||||
[node name="Reticle" type="CenterContainer" node_paths=PackedStringArray("reticle_lines")]
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
@ -82,6 +82,7 @@ anchor_bottom = 0.5
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = SubResource("GDScript_a8kpl")
|
||||
reticle_lines = [NodePath("top"), NodePath("left"), NodePath("right"), NodePath("bottom")]
|
||||
|
||||
[node name="dot" type="Polygon2D" parent="."]
|
||||
polygon = PackedVector2Array(-1, -1, 1, -1, 1, 1, -1, 1)
|
||||
|
Reference in New Issue
Block a user