changed equipped item logic for a more optimized one
title says all
This commit is contained in:
parent
b79eefdd59
commit
b32979e38b
2 changed files with 49 additions and 26 deletions
|
|
@ -17,6 +17,10 @@
|
||||||
|
|
||||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_g4v7s"]
|
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_g4v7s"]
|
||||||
|
|
||||||
|
[sub_resource type="PlaceholderMesh" id="PlaceholderMesh_60a4j"]
|
||||||
|
|
||||||
|
[sub_resource type="SphereShape3D" id="SphereShape3D_b5l5s"]
|
||||||
|
|
||||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_g4v7s"]
|
[sub_resource type="CylinderShape3D" id="CylinderShape3D_g4v7s"]
|
||||||
radius = 0.04638672
|
radius = 0.04638672
|
||||||
|
|
||||||
|
|
@ -112,9 +116,20 @@ unique_name_in_owner = true
|
||||||
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, -1, 0, 1, -4.371139e-08, 0, 0, 0)
|
transform = Transform3D(1, 0, 0, 0, -4.371139e-08, -1, 0, 1, -4.371139e-08, 0, 0, 0)
|
||||||
target_position = Vector3(0, -2, 0)
|
target_position = Vector3(0, -2, 0)
|
||||||
|
|
||||||
[node name="HoldPosition" type="Marker3D" parent="CameraPivot/PlayerCamera" unique_id=425231379]
|
[node name="EquippedItemPosition" type="RigidBody3D" parent="CameraPivot/PlayerCamera" unique_id=1800356500]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1.5698267)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, -1.5698267)
|
||||||
|
collision_layer = 0
|
||||||
|
collision_mask = 0
|
||||||
|
|
||||||
|
[node name="EquippedItemMesh" type="MeshInstance3D" parent="CameraPivot/PlayerCamera/EquippedItemPosition" unique_id=1561364797]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0.44286752, 0, 0.8769744)
|
||||||
|
mesh = SubResource("PlaceholderMesh_60a4j")
|
||||||
|
|
||||||
|
[node name="EquippedItemCollision" type="CollisionShape3D" parent="CameraPivot/PlayerCamera/EquippedItemPosition" unique_id=492114455]
|
||||||
|
transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0.44286752, 0, 0.8769744)
|
||||||
|
shape = SubResource("SphereShape3D_b5l5s")
|
||||||
|
|
||||||
[node name="GrabbableFinder" type="Area3D" parent="CameraPivot/PlayerCamera" unique_id=988433915]
|
[node name="GrabbableFinder" type="Area3D" parent="CameraPivot/PlayerCamera" unique_id=988433915]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ var inventory: Array[RigidBody3D] = [null,null]
|
||||||
|
|
||||||
@onready var ui: Control = %PlayerUi
|
@onready var ui: Control = %PlayerUi
|
||||||
@onready var flashlight: SpotLight3D = %Flashlight
|
@onready var flashlight: SpotLight3D = %Flashlight
|
||||||
@onready var selected_item_position: Marker3D = %SelectedItemPosition
|
@onready var equipped_item_mesh: MeshInstance3D = %EquippedItemMesh
|
||||||
|
|
||||||
var selected_item_object: RigidBody3D = null
|
var selected_item_object: RigidBody3D = null
|
||||||
|
|
||||||
|
|
@ -33,35 +33,45 @@ func select_item(index:int = selected_item):
|
||||||
if index >= 0 and index < len(inventory):
|
if index >= 0 and index < len(inventory):
|
||||||
ui.select_item(index)
|
ui.select_item(index)
|
||||||
|
|
||||||
#selecting empty slot makes all inventory items invisible
|
|
||||||
if inventory[index] == null:
|
if inventory[index] == null:
|
||||||
for c in selected_item_position.get_children():
|
#if current index is empty in the inventory, replace held object with placeholder (empty mesh)
|
||||||
c.visible = false
|
equipped_item_mesh.mesh = PlaceholderMesh.new()
|
||||||
return
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
#deselect item --> hide currently equipped item object
|
var mesh = null
|
||||||
#show newly selected item, since its not null because of the else statement it shouldnt crash
|
for i in inventory[index].get_children():
|
||||||
#if called from outside, sets the selected item to the index called from the argument
|
if i is MeshInstance3D:
|
||||||
if index != selected_item:
|
equipped_item_mesh.mesh = i.mesh
|
||||||
prev_selected_item = selected_item
|
|
||||||
if inventory[prev_selected_item] != null:
|
|
||||||
inventory[prev_selected_item].visible = false
|
#selecting empty slot makes all inventory items invisible
|
||||||
else:
|
#if inventory[index] == null:
|
||||||
if inventory[prev_selected_item] != null:
|
#for c in inventory:
|
||||||
inventory[prev_selected_item].visible = false
|
#c.visible = false
|
||||||
selected_item = index
|
#return
|
||||||
inventory[index].visible = true
|
#
|
||||||
|
#else:
|
||||||
|
##deselect item --> hide currently equipped item object
|
||||||
|
##show newly selected item, since its not null because of the else statement it shouldnt crash
|
||||||
|
##if called from outside, sets the selected item to the index called from the argument
|
||||||
|
#if index != selected_item:
|
||||||
|
#prev_selected_item = selected_item
|
||||||
|
#if inventory[prev_selected_item] != null:
|
||||||
|
#inventory[prev_selected_item].visible = false
|
||||||
|
#else:
|
||||||
|
#if inventory[prev_selected_item] != null:
|
||||||
|
#inventory[prev_selected_item].visible = false
|
||||||
|
#selected_item = index
|
||||||
|
#inventory[index].visible = true
|
||||||
|
|
||||||
func add_item(item: RigidBody3D):
|
func add_item(item: RigidBody3D):
|
||||||
#add item to current equipped slot if empty
|
#add item to current equipped slot if empty
|
||||||
if inventory[selected_item] == null:
|
if inventory[selected_item] == null:
|
||||||
inventory[selected_item] = item
|
inventory[selected_item] = item
|
||||||
ui.add_item(selected_item, item)
|
ui.add_item(selected_item, item)
|
||||||
item.reparent(selected_item_position)
|
item.reparent(get_parent().get_parent())
|
||||||
item.position = Vector3.ZERO
|
|
||||||
item.scale = Vector3(0.2, 0.2, 0.2)
|
|
||||||
item.collision_layer = 0
|
item.collision_layer = 0
|
||||||
|
item.visible = false
|
||||||
|
select_item(selected_item)
|
||||||
return
|
return
|
||||||
|
|
||||||
#add item to first empty slot if currently equipped slot is full
|
#add item to first empty slot if currently equipped slot is full
|
||||||
|
|
@ -69,9 +79,7 @@ func add_item(item: RigidBody3D):
|
||||||
if inventory[i] == null:
|
if inventory[i] == null:
|
||||||
inventory[i] = item
|
inventory[i] = item
|
||||||
ui.add_item(i, item)
|
ui.add_item(i, item)
|
||||||
item.reparent(selected_item_position)
|
item.reparent(get_parent().get_parent())
|
||||||
item.position = Vector3.ZERO
|
|
||||||
item.scale = Vector3(0.2, 0.2, 0.2)
|
|
||||||
item.collision_layer = 0
|
item.collision_layer = 0
|
||||||
item.visible = false
|
item.visible = false
|
||||||
return
|
return
|
||||||
|
|
@ -113,7 +121,7 @@ func _ready() -> void:
|
||||||
get_tree().create_timer(0.1).timeout.connect(func (): select_item(0))
|
get_tree().create_timer(0.1).timeout.connect(func (): select_item(0))
|
||||||
|
|
||||||
#func _physics_process(_delta: float) -> void:
|
#func _physics_process(_delta: float) -> void:
|
||||||
#handle equipped object
|
##handle equipped object
|
||||||
#if selected_item_object != null:
|
#if selected_item_object != null:
|
||||||
#var target_pos = selected_item_position.global_position
|
#var target_pos = selected_item_position.global_position
|
||||||
#var current_pos = selected_item_object.global_position
|
#var current_pos = selected_item_object.global_position
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue