Skip to content

Commit

Permalink
Merge pull request #114 from FailSpy/interactions-fix
Browse files Browse the repository at this point in the history
Make interactions be blocked by Environment safely
  • Loading branch information
Phazorknight authored Mar 13, 2024
2 parents 526f683 + e9f9c89 commit 05bcaf0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions COGITO/Components/PlayerInteractionComponent.gd
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ var is_changing_wieldables : bool = false #Used to avoid any input acitons while
var equipped_wieldable_item = null
var equipped_wieldable_node = null
var is_wielding : bool

var player_rid

func _ready():
#for node in wieldable_nodes:
#node.hide()
object_detected = false

func exclude_player(rid : RID):
player_rid = rid
interaction_raycast.add_exception_rid(rid)

func _process(_delta):
# when carrying object, disable all other prompts.
Expand Down Expand Up @@ -266,13 +269,14 @@ func send_hint(hint_icon,hint_text):

# This gets a world space collision point of whatever the camera is pointed at, depending on the equipped wieldable range.
func Get_Camera_Collision() -> Vector3:
var viewport = get_viewport().get_size()
var viewport = get_viewport().get_visible_rect().size
var camera = get_viewport().get_camera_3d()

var Ray_Origin = camera.project_ray_origin(viewport/2)
var Ray_End = Ray_Origin + camera.project_ray_normal(viewport/2)*equipped_wieldable_item.wieldable_range

var New_Intersection = PhysicsRayQueryParameters3D.create(Ray_Origin,Ray_End)
New_Intersection.exclude = [player_rid]
var Intersection = get_world_3d().direct_space_state.intersect_ray(New_Intersection)

if not Intersection.is_empty():
Expand Down
2 changes: 1 addition & 1 deletion COGITO/PrefabScenes/player.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ libraries = {

[node name="InteractionRaycast" type="RayCast3D" parent="Neck/Head/Eyes/Camera"]
target_position = Vector3(0, 0, -2.5)
collision_mask = 2
collision_mask = 3

[node name="Wieldables" type="Node3D" parent="Neck/Head"]

Expand Down
1 change: 1 addition & 0 deletions COGITO/Scripts/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func _ready():
#Some Setup steps
CogitoSceneManager._current_player_node = self
player_interaction_component.interaction_raycast = $Neck/Head/Eyes/Camera/InteractionRaycast
player_interaction_component.exclude_player(get_rid())

randomize()

Expand Down

0 comments on commit 05bcaf0

Please sign in to comment.