ggj2020

My game project for Global Game Jam 2020!
git clone git://git.hellocld.com/ggj2020
Log | Files | Refs

commit e90d9402c33be92639f2d0c8511ec26238a93d9b
parent c136ee69e28b3ddcc3d0e72433e187d32c4ee2b3
Author: Christopher Ray Langford <chris@hellocld.com>
Date:   Sat,  1 Feb 2020 12:25:45 -0500

Can grab objects, but physics not yet reenabling

- To fire off the grab/release signals (or handle any button input
  intelligently, really) be sure to subscribe to the
  button_pressed/button_released signals on ARVRController rather than
  polling is_button_pressed every frame
- Might want to look into joystick drift - might be a controller issue (
  D: ), might be a Godot issue

Diffstat:
AGrabbable.gd | 32++++++++++++++++++++++++++++++++
MGrabbyHand.gd | 19+++++++++++++------
APlayer/GrabbingArea.gd | 30++++++++++++++++++++++++++++++
APlayer/HandMesh.gd | 15+++++++++++++++
APlayer/Player.tscn | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
MSpatial.tscn | 72+++++++++++++++++++++++++++++++++++++++++-------------------------------
6 files changed, 185 insertions(+), 37 deletions(-)

diff --git a/Grabbable.gd b/Grabbable.gd @@ -0,0 +1,32 @@ +extends RigidBody + +onready var _parent = get_parent() +onready var _grabbed = false + + +func is_grabbed(): + return _grabbed + + +func _on_grabbed(var hand:ARVRController): + if _grabbed: + return + set_mode(RigidBody.MODE_STATIC) + get_parent().remove_child(self) + hand.add_child(self) + transform = Transform() + _grabbed = true + print("%s Grabbed" % name) + + +func _on_released(): + if !_grabbed: + return + var t = global_transform + set_mode(RigidBody.MODE_RIGID) + get_parent().remove_child(self) + _parent.add_child(self) + global_transform = t + + _grabbed = false + print("%s Released" % name) diff --git a/GrabbyHand.gd b/GrabbyHand.gd @@ -5,13 +5,20 @@ var _mesh_basis: Basis signal grabbing signal releasing + func _ready(): - _mesh_basis = $"Mesh".transform.basis + connect("button_pressed", self, "_grab") + connect("button_release", self, "_release") -func _process(delta): - if is_button_pressed(JOY_VR_GRIP): - $"Mesh".transform.basis = _mesh_basis.scaled(Vector3(0.5, 0.5, 0.5)) +func _grab(var btn): + if btn == JOY_VR_GRIP: + print("Grabbing") emit_signal("grabbing") - else: - $"Mesh".transform.basis = _mesh_basis + +func _release(var btn): + if btn == JOY_VR_GRIP: + print("Releasing") emit_signal("releasing") + +func is_grabbing() -> bool: + return true if is_button_pressed(JOY_VR_GRIP) else false diff --git a/Player/GrabbingArea.gd b/Player/GrabbingArea.gd @@ -0,0 +1,30 @@ +extends Area + +onready var controller: ARVRController = get_parent() + +var _grabbable + +func _ready(): + controller.connect("grabbing", self, "_grab_it") + controller.connect("releasing", self, "_let_go") + + +func _grab_it(): + if _grabbable != null and _grabbable.has_method("_on_grabbed"): + _grabbable.call("_on_grabbed", controller) + + +func _let_go(): + if _grabbable != null and _grabbable.has_method("_on_released"): + _grabbable.call("_on_released") + + +func _on_GrabbingArea_body_entered(body: PhysicsBody): + if body.has_method("_on_grabbed"): + _grabbable = body + else: + _grabbable = null + + +func _on_GrabbingArea_body_exited(body): + _grabbable = null diff --git a/Player/HandMesh.gd b/Player/HandMesh.gd @@ -0,0 +1,15 @@ +extends MeshInstance + +var _default_basis: Basis + +func _ready(): + _default_basis = transform.basis + get_parent().connect("grabbing", self, "_on_grabbing") + get_parent().connect("releasing", self, "_on_releasing") + +func _on_grabbing(): + transform.basis = _default_basis.scaled(Vector3.ONE * 0.5) + + +func _on_releasing(): + transform.basis = _default_basis diff --git a/Player/Player.tscn b/Player/Player.tscn @@ -0,0 +1,54 @@ +[gd_scene load_steps=7 format=2] + +[ext_resource path="res://GrabbyHand.gd" type="Script" id=1] +[ext_resource path="res://ARVROrigin.gd" type="Script" id=2] +[ext_resource path="res://Player/HandMesh.gd" type="Script" id=3] +[ext_resource path="res://Player/GrabbingArea.gd" type="Script" id=4] + +[sub_resource type="PrismMesh" id=1] +size = Vector3( 0.25, 0.25, 0.25 ) + +[sub_resource type="SphereShape" id=2] +radius = 0.25 + +[node name="Player" type="ARVROrigin"] +script = ExtResource( 2 ) + +[node name="ARVRCamera" type="ARVRCamera" parent="."] + +[node name="LeftController" type="ARVRController" parent="."] +script = ExtResource( 1 ) + +[node name="HandMesh" type="MeshInstance" parent="LeftController"] +transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0 ) +mesh = SubResource( 1 ) +material/0 = null +script = ExtResource( 3 ) + +[node name="GrabbingArea" type="Area" parent="LeftController"] +script = ExtResource( 4 ) + +[node name="CollisionShape" type="CollisionShape" parent="LeftController/GrabbingArea"] +shape = SubResource( 2 ) + +[node name="RightController" type="ARVRController" parent="."] +controller_id = 2 +script = ExtResource( 1 ) + +[node name="HandMesh" type="MeshInstance" parent="RightController"] +transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0 ) +mesh = SubResource( 1 ) +material/0 = null +script = ExtResource( 3 ) + +[node name="GrabbingArea" type="Area" parent="RightController"] +script = ExtResource( 4 ) + +[node name="CollisionShape" type="CollisionShape" parent="RightController/GrabbingArea"] +shape = SubResource( 2 ) + +[node name="PlayerPos" type="Spatial" parent="."] +[connection signal="body_entered" from="LeftController/GrabbingArea" to="LeftController/GrabbingArea" method="_on_GrabbingArea_body_entered"] +[connection signal="body_exited" from="LeftController/GrabbingArea" to="LeftController/GrabbingArea" method="_on_GrabbingArea_body_exited"] +[connection signal="body_entered" from="RightController/GrabbingArea" to="RightController/GrabbingArea" method="_on_GrabbingArea_body_entered"] +[connection signal="body_exited" from="RightController/GrabbingArea" to="RightController/GrabbingArea" method="_on_GrabbingArea_body_exited"] diff --git a/Spatial.tscn b/Spatial.tscn @@ -1,54 +1,64 @@ -[gd_scene load_steps=8 format=2] +[gd_scene load_steps=11 format=2] [ext_resource path="res://Spatial.gd" type="Script" id=1] -[ext_resource path="res://ARVROrigin.gd" type="Script" id=2] -[ext_resource path="res://GrabbyHand.gd" type="Script" id=3] - -[sub_resource type="PrismMesh" id=3] -size = Vector3( 0.25, 0.25, 0.25 ) +[ext_resource path="res://Player/Player.tscn" type="PackedScene" id=2] +[ext_resource path="res://Grabbable.gd" type="Script" id=3] [sub_resource type="PlaneMesh" id=1] size = Vector2( 50, 50 ) -[sub_resource type="SpatialMaterial" id=6] +[sub_resource type="SpatialMaterial" id=2] albedo_color = Color( 0.247059, 0.705882, 0.352941, 1 ) -[sub_resource type="PrismMesh" id=2] +[sub_resource type="ConcavePolygonShape" id=3] +data = PoolVector3Array( 25, 0, 25, -25, 0, 25, 25, 0, -25, -25, 0, 25, -25, 0, -25, 25, 0, -25 ) + +[sub_resource type="CylinderShape" id=4] +radius = 0.5 +height = 1.0 + +[sub_resource type="SpatialMaterial" id=6] +albedo_color = Color( 0.831373, 0.0666667, 0.0666667, 1 ) + +[sub_resource type="CylinderMesh" id=7] +material = SubResource( 6 ) +top_radius = 0.4 +bottom_radius = 0.4 +height = 0.8 + +[sub_resource type="CylinderMesh" id=5] +top_radius = 0.5 +bottom_radius = 0.5 +height = 1.0 +radial_segments = 16 [node name="Spatial" type="Spatial"] script = ExtResource( 1 ) -[node name="ARVROrigin" type="ARVROrigin" parent="."] -script = ExtResource( 2 ) +[node name="Player" parent="." instance=ExtResource( 2 )] -[node name="ARVRCamera" type="ARVRCamera" parent="ARVROrigin"] +[node name="Floor" type="MeshInstance" parent="."] +mesh = SubResource( 1 ) +material/0 = SubResource( 2 ) -[node name="LeftController" type="ARVRController" parent="ARVROrigin"] -script = ExtResource( 3 ) +[node name="StaticBody" type="StaticBody" parent="Floor"] -[node name="Mesh" type="MeshInstance" parent="ARVROrigin/LeftController"] -transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0 ) -mesh = SubResource( 3 ) -material/0 = null +[node name="CollisionShape" type="CollisionShape" parent="Floor/StaticBody"] +shape = SubResource( 3 ) -[node name="RightController" type="ARVRController" parent="ARVROrigin"] -controller_id = 2 +[node name="Grabbable" type="RigidBody" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.21566, 8.72828 ) script = ExtResource( 3 ) -[node name="Mesh" type="MeshInstance" parent="ARVROrigin/RightController"] -transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0 ) -mesh = SubResource( 3 ) -material/0 = null - -[node name="PlayerPos" type="Spatial" parent="ARVROrigin"] +[node name="CollisionShape" type="CollisionShape" parent="Grabbable"] +shape = SubResource( 4 ) -[node name="Floor" type="MeshInstance" parent="."] -mesh = SubResource( 1 ) -material/0 = SubResource( 6 ) +[node name="MeshInstance" type="MeshInstance" parent="Grabbable/CollisionShape"] +mesh = SubResource( 7 ) +material/0 = null -[node name="MeshInstance" type="MeshInstance" parent="."] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, -4 ) -mesh = SubResource( 2 ) +[node name="Cone" type="MeshInstance" parent="Grabbable"] +mesh = SubResource( 5 ) material/0 = null [node name="DirectionalLight" type="DirectionalLight" parent="."]