ggj2020

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

commit c136ee69e28b3ddcc3d0e72433e187d32c4ee2b3
parent 71a6a5f9cd135488b9fe829f3455b639bd372c49
Author: Christopher Ray Langford <chris@hellocld.com>
Date:   Fri, 31 Jan 2020 23:06:47 -0500

Fixed controller drift. Started messing with "grabbing"

Turns out putting your player movement stuff in _process() is a *bad*
idea. Stick it in _physics_process and poof, problem solved.

Diffstat:
MARVROrigin.gd | 16++++++++--------
AGrabbyHand.gd | 17+++++++++++++++++
MSpatial.tscn | 26+++++++-------------------
3 files changed, 32 insertions(+), 27 deletions(-)

diff --git a/ARVROrigin.gd b/ARVROrigin.gd @@ -3,21 +3,21 @@ export var _speed: int = 10 var _can_turn = true var _rotation: float +var _rot_increment: int = 30 - -func _process(delta): - var r_stick = Vector2($"ARVRRightController".get_joystick_axis(0), - $"ARVRRightController".get_joystick_axis(1)) +func _physics_process(delta): + var r_stick = Vector2($"RightController".get_joystick_axis(0), + $"RightController".get_joystick_axis(1)) - var cam_basis = $"ARVRCamera".transform.basis - var turn = $"ARVRLeftController".get_joystick_axis(0) + var cam_basis = ARVRServer.get_hmd_transform().basis + var turn = $"LeftController".get_joystick_axis(0) if abs(turn) > 0.5 && _can_turn: _can_turn = false if turn > 0: - _rotation = 10 + _rotation = -_rot_increment else: - _rotation = -10 + _rotation = _rot_increment rotate(Vector3.UP, deg2rad(_rotation)) cam_basis = cam_basis.rotated(Vector3.UP, _rotation) if !_can_turn && abs(turn) < 0.5: diff --git a/GrabbyHand.gd b/GrabbyHand.gd @@ -0,0 +1,17 @@ +extends ARVRController + +var _mesh_basis: Basis + +signal grabbing +signal releasing + +func _ready(): + _mesh_basis = $"Mesh".transform.basis + +func _process(delta): + if is_button_pressed(JOY_VR_GRIP): + $"Mesh".transform.basis = _mesh_basis.scaled(Vector3(0.5, 0.5, 0.5)) + emit_signal("grabbing") + else: + $"Mesh".transform.basis = _mesh_basis + emit_signal("releasing") diff --git a/Spatial.tscn b/Spatial.tscn @@ -2,24 +2,11 @@ [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 ) -[sub_resource type="GDScript" id=7] -script/source = "extends ARVRController - -# Joystick axis -# 0 - Touchpad/Joystick X -# 1 - Touchpad/Joystick Y -# 2 - Analog Trigger -# 3 - Nothing? - -# Buttons -# - -" - [sub_resource type="PlaneMesh" id=1] size = Vector2( 50, 50 ) @@ -36,18 +23,19 @@ script = ExtResource( 2 ) [node name="ARVRCamera" type="ARVRCamera" parent="ARVROrigin"] -[node name="ARVRLeftController" type="ARVRController" parent="ARVROrigin"] +[node name="LeftController" type="ARVRController" parent="ARVROrigin"] +script = ExtResource( 3 ) -[node name="MeshInstance" type="MeshInstance" parent="ARVROrigin/ARVRLeftController"] +[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="ARVRRightController" type="ARVRController" parent="ARVROrigin"] +[node name="RightController" type="ARVRController" parent="ARVROrigin"] controller_id = 2 -script = SubResource( 7 ) +script = ExtResource( 3 ) -[node name="MeshInstance2" type="MeshInstance" parent="ARVROrigin/ARVRRightController"] +[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