Skip to content

Commit

Permalink
VR tutorial cleanup and code refactor (#3)
Browse files Browse the repository at this point in the history
Adds the following commits from PR #3 
________________________________________

* Made a bunch of changes to the VR tutorial project.

* Added rumble when objects are picked up, the guns are fired, and when the sword collides with something.
* Added a raycast "laser sight" to the Shotgun for easier aiming
* Added a new knockback/collision-force system to the pistol, shotgun, and bomb objects. Now the closer the object is to the collision, the farther it goes.
  * This change also makes the bombs a little more consistent and natural looking.
* Created a base class, VR_Interactable_Rigidbody, to use for all interactable Rigidbodies in the game.
* Changed the code within the VR controller to use VR_Interactable_Rigidbody instead of checking for methods.
* Fixed issue where the shotgun raycasts would send targets towards the player. Now when the shotgun fires, objects hit fly away from the end of the shotgun.
* Fixed issue where the meshes used for teleportation and raycast-grabbing in the VR controller were initially visible. Now the meshes are only visible when the player starts teleporting and/or changes grab modes.
* I probably forgot a few minor changes...

* Refactored the VR controller script and moved it into the Scenes folder.

The refactoring is mainly just breaking everything out into smaller functions, with little changes to the code. The comments within the code still need updating/fixing.

Refactoring may have broken/changed the controller velocity stuff. The code itself has not changed, but in my tests I couldn't quite get throwing to work. It might be my VR headset though.
I will need to do more tests to figure out what is going on.

* Redid the VR sword. Now it is much more accurate and usable, at the cost of needing to use a KinematicBody instead of an Area node. I'm not sure what, if any, performance impact this has.
The entire sword feels MUCH more realistic now and the code is a lot more compact and easy to understand. In my opinion, any minor performance loss is worth it for the improve collision detection
and better code.

I also change the damage function in Sphere_Target.gd, as the passed-in transform was not needed.

* Made the main VR gui node its own scene, renamed and moved the Base_Control script to the scenes folder, and moved the GUI script to the scenes folder

* Updated the comments in the code for the first half of the VR project. The Reset_Box, Shotgun, Sphere_Target, Sword, and VR_Controller files still need updating

* Finished updating the comments within all of the code files. Now everything has up-to-date comments explaining what the code does

* Minor fixes and changes made while writing the tutorial for the Godot documentation

* More slight changes made while working on the tutorial rewrite

* Changes made to the reset box script while working on the VR starter tutorial for the Godot documentation
  • Loading branch information
TwistedTwigleg authored Oct 26, 2019
1 parent 585f197 commit 7d1914e
Show file tree
Hide file tree
Showing 28 changed files with 1,353 additions and 2,248 deletions.
25 changes: 0 additions & 25 deletions Base_Control.gd

This file was deleted.

26 changes: 0 additions & 26 deletions GUI.gd

This file was deleted.

28 changes: 17 additions & 11 deletions Game.gd
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
extends Spatial

# The amount of sphere's left to destroy
# A variable to store the amount of spheres in the scene
# This is used to track whether all of the spheres in the scene have been destoyed
var spheres_left = 10
# A variable to store the UI used for the sphere count.
# This variable is assumed to be set by Main_VR_UI_Base_Control.gd
var sphere_ui = null


func _ready():

# We will be using OpenVR to drive the VR interface, so we need to find and initialize it.
var VR = ARVRServer.find_interface("OpenVR")
# We will be using OpenVR to drive the VR interface, so we need to find it.
var VR = ARVRServer.find_interface("OpenVR");
# If the OpenVR interface was found and initialization is successful...
if VR and VR.initialize():

# Turn the main viewport into a AR/VR viewport,
# and turn off HDR (which currently does not work)
# Turn the main viewport into a AR/VR viewport and turn off HDR
get_viewport().arvr = true
get_viewport().hdr = false

# Let's disable VSync so we are not running at whatever the monitor's VSync is,
# and let's set the target FPS to 90, which is standard for most VR headsets.
# Let's disable VSync so the FPS is not capped and set the target FPS to 90,
# which is standard for most VR headsets.
#
# This is not strictly required, but it will make the experience smoother for most VR headsets
# and then the computer monitor's VSync will not effect the VR headset.
OS.vsync_enabled = false
Engine.target_fps = 90
# Also, the physics FPS in the project settings is also 90 FPS. This makes the physics
# run at the same frame rate as the display, which makes things look smoother in VR!
# run at the same frame rate as the display, which makes things look a little smoother in VR!


func remove_sphere():
# Remove a sphere
# Remove one from the spheres_left variable
spheres_left -= 1

# If we have a node attached to sphere_ui, then we want to update it!
# If sphere_ui is not null, then assume it is set to a node with Main_VR_UI_Base_Control.gd
# and call the update_ui function
if sphere_ui != null:
sphere_ui.update_ui(spheres_left)

Loading

0 comments on commit 7d1914e

Please sign in to comment.