-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified XRToolsPlayerBody to use the ARVROrigin basis.y for its up v…
…ector. Added demo scene with ground-following movement provider to test the new up-vector logic. Added player orientation provider support to the XRToolsPlayerBody. Added ground and area orientation providers. Added path, point, and uniform orient areas to control the player orientation in different areas. Enhanced origin gravity demo to use orient areas to better handle player movement around the sphere and pill shapes. Removed experimental world-grab provider not intended for this PR
- Loading branch information
1 parent
05f7d20
commit f631ca9
Showing
27 changed files
with
911 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
tool | ||
class_name XRToolsOrientationArea | ||
extends XRToolsOrientationProvider | ||
|
||
|
||
## XR Tools Area Orientation Provider | ||
## | ||
## This orientation provider orients the player based on orient areas the player | ||
## enters. | ||
|
||
|
||
## Movement provider order | ||
export var order : int = 20 | ||
|
||
# Set our collision mask | ||
export (int, LAYERS_3D_PHYSICS) var collision_mask : int = 524288 | ||
|
||
|
||
# Orient sense area | ||
var _sense_area : Area | ||
|
||
# Array of orientation areas the player is in | ||
var _orient_areas := Array() | ||
|
||
|
||
# Add support for is_class on XRTools classes | ||
func is_class(name : String) -> bool: | ||
return name == "XRToolsOrientationArea" or .is_class(name) | ||
|
||
|
||
# Called when the node enters the scene tree for the first time. | ||
func _ready(): | ||
# Skip if running in the editor | ||
if Engine.editor_hint: | ||
return | ||
|
||
# Skip if we don't have a player | ||
var player := XRToolsPlayerBody.find_instance(self) | ||
if !player: | ||
return | ||
|
||
# Construct the sphere shape | ||
var sphere_shape := SphereShape.new() | ||
sphere_shape.radius = 0.3 | ||
|
||
# Construct the collision shape | ||
var collision_shape := CollisionShape.new() | ||
collision_shape.set_name("OrientSensorShape") | ||
collision_shape.shape = sphere_shape | ||
|
||
# Construct the sense area | ||
_sense_area = Area.new() | ||
_sense_area.set_name("OrientSensorArea") | ||
_sense_area.collision_mask = collision_mask | ||
_sense_area.add_child(collision_shape) | ||
|
||
# Add the sense area to the players body (feet) | ||
player.kinematic_node.add_child(_sense_area) | ||
|
||
# Subscribe to area notifications | ||
_sense_area.connect("area_entered", self, "_on_area_entered") | ||
_sense_area.connect("area_exited", self, "_on_area_exited") | ||
|
||
|
||
## Perform player orientation to ground | ||
func physics_orientation(_delta: float, _player_body: XRToolsPlayerBody) -> bool: | ||
# Skip if not in any orient areas | ||
if _orient_areas.size() == 0: | ||
return false | ||
|
||
# Get the highest priority area | ||
var area : XRToolsOrientArea = _orient_areas.front() | ||
|
||
# If enabled, override player gravity | ||
if area.override_player_gravity: | ||
_player_body.gravity = area.player_gravity | ||
|
||
# Get the up vector and orient the player | ||
var up := area.get_up(_player_body.kinematic_node.global_translation) | ||
_player_body.slew_up(up, _delta * area.slew_rate) | ||
return true | ||
|
||
|
||
func _on_area_entered(area: Area): | ||
# Skip if not orient area | ||
var orient_area = area as XRToolsOrientArea | ||
if !orient_area: | ||
return | ||
|
||
# Iterate over all areas in the list | ||
for pos in _orient_areas.size(): | ||
# Get the area in the list | ||
var a : XRToolsOrientArea = _orient_areas[pos] | ||
|
||
# Insert before lower priorities | ||
if a.priority <= orient_area.priority: | ||
_orient_areas.insert(pos, orient_area) | ||
return | ||
|
||
# Insert at the end | ||
_orient_areas.push_back(orient_area) | ||
|
||
|
||
func _on_area_exited(area: Area): | ||
# Erase the area from the list | ||
_orient_areas.erase(area) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[gd_scene load_steps=2 format=2] | ||
|
||
[ext_resource path="res://addons/godot-xr-tools/functions/orientation_area.gd" type="Script" id=1] | ||
|
||
[node name="OrientationArea" type="Node" groups=["orientation_providers"]] | ||
script = ExtResource( 1 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
tool | ||
class_name XRToolsOrientationGround | ||
extends XRToolsOrientationProvider | ||
|
||
|
||
## XR Tools Ground Orientation Provider | ||
## | ||
## This ground orientation provider orients the player on any ground surface | ||
## whose physics layer matches the follow mask | ||
|
||
|
||
## Orientation provider order | ||
export var order : int = 10 | ||
|
||
## Slew rate when on ground | ||
export var ground_slew_rate : float = 5.0 | ||
|
||
# Set our follow layer mask | ||
export (int, LAYERS_3D_PHYSICS) var follow_mask : int = 1023 | ||
|
||
## If true, player gravity is modified when the player touches the ground | ||
export var override_player_gravity : bool = false | ||
|
||
## Player gravity | ||
export var player_gravity : float = -9.8 | ||
|
||
|
||
## Perform player orientation to ground | ||
func physics_orientation(_delta: float, _player_body: XRToolsPlayerBody) -> bool: | ||
# Skip if not in contact with ground | ||
if not _player_body.on_ground: | ||
return false | ||
|
||
# Skip if the ground node doesn't have a collision layer | ||
if not "collision_layer" in _player_body.ground_node: | ||
return false | ||
|
||
# Skip if the ground doesn't have the follow layer | ||
var ground_layer : int = _player_body.ground_node.collision_layer | ||
if (ground_layer & follow_mask) == 0: | ||
return false | ||
|
||
# Override player gravity if requested | ||
if override_player_gravity: | ||
_player_body.gravity = player_gravity | ||
|
||
# Slew the player to align with the ground | ||
_player_body.slew_up(_player_body.ground_vector, _delta * ground_slew_rate) | ||
return true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[gd_scene load_steps=2 format=2] | ||
|
||
[ext_resource path="res://addons/godot-xr-tools/functions/orientation_ground.gd" type="Script" id=1] | ||
|
||
[node name="OrientationGround" type="Node" groups=["orientation_providers"]] | ||
script = ExtResource( 1 ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
tool | ||
class_name XRToolsOrientationProvider, "res://addons/godot-xr-tools/editor/icons/node.svg" | ||
extends XRToolsPlayerProvider | ||
|
||
|
||
## XR Tools Orientation Provider base class | ||
## | ||
## This orientation provider class is the base class of all orientation | ||
## providers. Orientation providers are invoked by the [XRToolsPlayerBody] | ||
## object in order to orient the players up direction in the world. | ||
|
||
|
||
## Add support for is_class on XRTools classes | ||
func is_class(name : String) -> bool: | ||
return name == "XRToolsOrientationProvider" or .is_class(name) | ||
|
||
|
||
## Override this function to apply orientation to the PlayerBody | ||
func physics_orientation(_delta: float, _player_body: XRToolsPlayerBody) -> bool: | ||
return false | ||
|
||
|
||
## This method verifies the movement provider has a valid configuration. | ||
func _get_configuration_warning(): | ||
# Verify orientation provider is in the correct group | ||
if !is_in_group("orientation_providers"): | ||
return "Orientation provider not in 'orientation_providers' group" | ||
|
||
# Verify order property exists | ||
if !"order" in self: | ||
return "Orientation provider does not expose an order property" | ||
|
||
# Call base class | ||
return ._get_configuration_warning() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
tool | ||
class_name XRToolsOrientArea, "res://addons/godot-xr-tools/editor/icons/node.svg" | ||
extends Area | ||
|
||
|
||
## XR Tools Orient Area base class | ||
## | ||
## This is the base class for orient areas which affect the players orientation. | ||
## The player must have an [XRToolsOrientationArea] provider attached for | ||
## orient areas to be processed. | ||
|
||
|
||
## Slew rate for setting orientation | ||
export var slew_rate : float = 5.0 | ||
|
||
## If true, player gravity is modified when the player enters the area | ||
export var override_player_gravity : bool = false | ||
|
||
## Player gravity | ||
export var player_gravity : float = -9.8 | ||
|
||
|
||
## Add support for is_class on XRTools classes | ||
func is_class(name : String) -> bool: | ||
return name == "XRToolsOrientationArea" or .is_class(name) | ||
|
||
|
||
## Get the up vector for the specified position | ||
func get_up(_position: Vector3) -> Vector3: | ||
return Vector3.UP |
Oops, something went wrong.