-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #340 from Phazorknight/auto-pick-up-zone
Adds an AutoPickUpZone to the player
- Loading branch information
Showing
6 changed files
with
185 additions
and
1 deletion.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
addons/cogito/Assets/Graphics/Editor/Icon_AutoPickUpZone.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions
37
addons/cogito/Assets/Graphics/Editor/Icon_AutoPickUpZone.svg.import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[remap] | ||
|
||
importer="texture" | ||
type="CompressedTexture2D" | ||
uid="uid://bbt1hw8oekefc" | ||
path="res://.godot/imported/Icon_AutoPickUpZone.svg-d67018c19bfb70773473a113052db674.ctex" | ||
metadata={ | ||
"vram_texture": false | ||
} | ||
|
||
[deps] | ||
|
||
source_file="res://addons/cogito/Assets/Graphics/Editor/Icon_AutoPickUpZone.svg" | ||
dest_files=["res://.godot/imported/Icon_AutoPickUpZone.svg-d67018c19bfb70773473a113052db674.ctex"] | ||
|
||
[params] | ||
|
||
compress/mode=0 | ||
compress/high_quality=false | ||
compress/lossy_quality=0.7 | ||
compress/hdr_compression=1 | ||
compress/normal_map=0 | ||
compress/channel_pack=0 | ||
mipmaps/generate=false | ||
mipmaps/limit=-1 | ||
roughness/mode=0 | ||
roughness/src_normal="" | ||
process/fix_alpha_border=true | ||
process/premult_alpha=false | ||
process/normal_map_invert_y=false | ||
process/hdr_as_srgb=false | ||
process/hdr_clamp_exposure=false | ||
process/size_limit=0 | ||
detect_3d/compress_to=1 | ||
svg/scale=1.0 | ||
editor/scale_with_editor_scale=false | ||
editor/convert_colors_with_editor_theme=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
@icon("res://addons/cogito/Assets/Graphics/Editor/Icon_AutoPickUpZone.svg") | ||
class_name AutoPickUpZone | ||
extends Area3D | ||
|
||
signal auto_picked_up_item() | ||
|
||
# This is useful when you have pick up items that are frustrating, tedious, or required | ||
# and provides a smoother experience than only using the default raycasting + input interaction. | ||
|
||
## Items listed here will be picked up automatically when they enter the area | ||
@export var auto_pick_up_items: Array[InventoryItemPD] = [] | ||
@export var _player_interaction_component: PlayerInteractionComponent | ||
var player: CogitoPlayer | ||
@onready var standing_collider: CollisionShape3D = $StandingZone | ||
@onready var crouching_collider: CollisionShape3D = $CrouchingZone | ||
|
||
|
||
func _ready() -> void: | ||
player = get_parent() | ||
|
||
|
||
func _on_body_entered(body: Node3D) -> void: | ||
_attempt_pick_up(body) | ||
|
||
|
||
func _physics_process(_delta) -> void: | ||
_update_shape() | ||
|
||
|
||
func _update_shape() -> void: | ||
# Uses a shorter collision cylinder when crouching | ||
if player.is_crouching: | ||
if !standing_collider.disabled: | ||
standing_collider.disabled = true | ||
if crouching_collider.disabled: | ||
crouching_collider.disabled = false | ||
else: | ||
if standing_collider.disabled: | ||
standing_collider.disabled = false | ||
if !crouching_collider.disabled: | ||
crouching_collider.disabled = true | ||
|
||
|
||
func _attempt_pick_up(body: Node3D) -> void: | ||
var child_count: int = body.get_child_count() | ||
# search recursively as PickupComponents tend to be childed near the back | ||
for i in range(child_count-1, -1, -1): | ||
if body.get_child(i) is not PickupComponent: | ||
continue | ||
|
||
var pick_up_component = body.get_child(i) as PickupComponent | ||
# This prevents cogito projectiles | ||
if body is CogitoProjectile and !(body as CogitoProjectile).can_pick_up: | ||
#print("can't pick up projectile as it has just been fired") | ||
continue | ||
|
||
if auto_pick_up_items.has(pick_up_component.slot_data.inventory_item): | ||
pick_up_component.interact(_player_interaction_component) | ||
auto_picked_up_item.emit() | ||
# Exit loop after detecting a pick up component (should only be one) | ||
break | ||
|
||
|
||
# TODO: may require save functionality to properly implement altering the item list | ||
#func new_item_list(new_items: Array[InventoryItemPD]) -> void: | ||
#auto_pick_up_items = new_items.duplicate() | ||
#CogitoGlobals.debug_log(true,"AutoPickUpZone.gd", "Created a new auto pick up list") | ||
# | ||
# | ||
#func add_item_to_list(item: InventoryItemPD) -> void: | ||
#if !auto_pick_up_items.has(item): | ||
#auto_pick_up_items.append(item) | ||
#CogitoGlobals.debug_log(true,"AutoPickUpZone.gd", "Added %s to auto pick up list" % item.name) | ||
# | ||
# | ||
#func remove_item_from_list(item: InventoryItemPD) -> void: | ||
#if auto_pick_up_items.has(item): | ||
#auto_pick_up_items.erase(item) | ||
#CogitoGlobals.debug_log(true,"AutoPickUpZone.gd", "Removed %s from auto pick up list" % item.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[gd_scene load_steps=8 format=3 uid="uid://cga0lxak2u2oq"] | ||
|
||
[ext_resource type="Script" path="res://addons/cogito/Components/AutoPickUpZone.gd" id="1_nbis2"] | ||
[ext_resource type="Script" path="res://addons/cogito/InventoryPD/CustomResources/InventoryItemPD.gd" id="2_ulsma"] | ||
[ext_resource type="Resource" uid="uid://bqhbrpnp2tt08" path="res://addons/cogito/InventoryPD/Items/Cogito_FoamBullets.tres" id="3_jp7wc"] | ||
[ext_resource type="Resource" uid="uid://cvupo3p844nh2" path="res://addons/cogito/InventoryPD/Items/Cogito_LaserAmmo.tres" id="4_mlplg"] | ||
[ext_resource type="Resource" uid="uid://cupby6uqaftvv" path="res://addons/cogito/InventoryPD/Items/Cogito_Battery.tres" id="5_3whxy"] | ||
|
||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_cn2h2"] | ||
height = 1.5 | ||
radius = 0.75 | ||
|
||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_fawea"] | ||
height = 1.0 | ||
radius = 0.75 | ||
|
||
[node name="AutoPickUpZone" type="Area3D"] | ||
collision_layer = 0 | ||
collision_mask = 2 | ||
script = ExtResource("1_nbis2") | ||
auto_pick_up_items = Array[ExtResource("2_ulsma")]([ExtResource("3_jp7wc"), ExtResource("4_mlplg"), ExtResource("5_3whxy")]) | ||
|
||
[node name="StandingZone" type="CollisionShape3D" parent="."] | ||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.25, 0) | ||
shape = SubResource("CylinderShape3D_cn2h2") | ||
|
||
[node name="CrouchingZone" type="CollisionShape3D" parent="."] | ||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.5, 0) | ||
shape = SubResource("CylinderShape3D_fawea") | ||
|
||
[connection signal="body_entered" from="." to="." method="_on_body_entered"] | ||
[connection signal="body_exited" from="." to="." method="_on_body_exited"] |
Oops, something went wrong.