ggj2020

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

commit 5db0c9e7aba34ace603033325e134566fec6e9ae
parent e489c0d30d636d069183f50d9004558eb1844f8c
Author: Christopher Ray Langford <chris@hellocld.com>
Date:   Sat,  1 Feb 2020 14:02:28 -0500

Throwing works

It's not perfect, but you can throw stuff now. One thing that's notably
broken is turning with the left stick breaks the calculated velocity (it
doesn't take the virtual orientation into account in _get_velocity())

Diffstat:
MGrabbable.gd | 6+++---
MGrabbyHand.gd | 26++++++++++++++++++++++++--
MPlayer/GrabbingArea.gd | 4++--
MPlayer/HandMesh.gd | 2+-
MSpatial.tscn | 26++++++++++++++++++++------
5 files changed, 50 insertions(+), 14 deletions(-)

diff --git a/Grabbable.gd b/Grabbable.gd @@ -19,7 +19,7 @@ func _on_grabbed(var hand:ARVRController): print("%s Grabbed" % name) -func _on_released(): +func _on_released(var vel): if !_grabbed: return var t = global_transform @@ -27,7 +27,7 @@ func _on_released(): _parent.add_child(self) global_transform = t mode = RigidBody.MODE_RIGID - - + apply_impulse(Vector3.ZERO, vel) + print("Impulse %s applied" % vel) _grabbed = false print("%s Released" % name) diff --git a/GrabbyHand.gd b/GrabbyHand.gd @@ -1,24 +1,46 @@ extends ARVRController var _mesh_basis: Basis +onready var _velocity_queue = [] +var _queue_size = 60 +onready var _last_pos = transform.origin signal grabbing -signal releasing +signal releasing(velocity) func _ready(): connect("button_pressed", self, "_grab") connect("button_release", self, "_release") + +func _physics_process(delta): + _velocity_queue.push_back(transform.origin - _last_pos) + _last_pos = transform.origin + if _velocity_queue.size() > _queue_size: + _velocity_queue.pop_front() + + func _grab(var btn): if btn == JOY_VR_GRIP: print("Grabbing") + _velocity_queue.clear() emit_signal("grabbing") + func _release(var btn): if btn == JOY_VR_GRIP: print("Releasing") - emit_signal("releasing") + print(_get_velocity()) + emit_signal("releasing", _get_velocity()) + func is_grabbing() -> bool: return true if is_button_pressed(JOY_VR_GRIP) else false + + +func _get_velocity() -> Vector3: + var vel = Vector3.ZERO + for i in range(_velocity_queue.size()): + vel += (_velocity_queue[i] * i) + return vel diff --git a/Player/GrabbingArea.gd b/Player/GrabbingArea.gd @@ -14,9 +14,9 @@ func _grab_it(): _grabbable.call("_on_grabbed", controller) -func _let_go(): +func _let_go(vel): if _grabbable != null and _grabbable.has_method("_on_released"): - _grabbable.call("_on_released") + _grabbable.call("_on_released", vel) func _on_GrabbingArea_body_entered(body: PhysicsBody): diff --git a/Player/HandMesh.gd b/Player/HandMesh.gd @@ -11,5 +11,5 @@ func _on_grabbing(): transform.basis = _default_basis.scaled(Vector3.ONE * 0.5) -func _on_releasing(): +func _on_releasing(vel): transform.basis = _default_basis diff --git a/Spatial.tscn b/Spatial.tscn @@ -1,17 +1,30 @@ -[gd_scene load_steps=9 format=2] +[gd_scene load_steps=11 format=2] [ext_resource path="res://Spatial.gd" type="Script" id=1] [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 ) +size = Vector2( 100, 100 ) + +[sub_resource type="OpenSimplexNoise" id=7] +persistence = 1.0 +lacunarity = 3.0 + +[sub_resource type="NoiseTexture" id=8] +seamless = true +as_normalmap = true +bump_strength = 12.0 +noise = SubResource( 7 ) [sub_resource type="SpatialMaterial" id=2] albedo_color = Color( 0.247059, 0.705882, 0.352941, 1 ) +normal_enabled = true +normal_scale = 1.0 +normal_texture = SubResource( 8 ) -[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="ConcavePolygonShape" id=9] +data = PoolVector3Array( 50, 0, 50, -50, 0, 50, 50, 0, -50, -50, 0, 50, -50, 0, -50, 50, 0, -50 ) [sub_resource type="CylinderShape" id=4] radius = 0.5 @@ -35,10 +48,11 @@ material/0 = SubResource( 2 ) [node name="StaticBody" type="StaticBody" parent="Floor"] [node name="CollisionShape" type="CollisionShape" parent="Floor/StaticBody"] -shape = SubResource( 3 ) +shape = SubResource( 9 ) [node name="Grabbable" type="RigidBody" parent="."] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2.21566, 8.72828 ) +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.88499, 8.72828 ) +mass = 2.04082 script = ExtResource( 3 ) [node name="CollisionShape" type="CollisionShape" parent="Grabbable"]