Skip to content

Commit

Permalink
Merge flapping improvement from 3.x branch (#432)
Browse files Browse the repository at this point in the history
Merged additional fixes for Grab Handles layer and usage.
  • Loading branch information
Malcolmnixon committed Apr 8, 2023
1 parent acacffd commit ba5641f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 34 deletions.
1 change: 1 addition & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# 4.1.0 (development)
- Enhanced grappling to support collision and target layers
- Added Godot Editor XR Tools menu for layers and openxr configuration
- Improved gliding to support roll-turning while flapping

# 4.0.0
- Conversion to Godot 4
Expand Down
26 changes: 12 additions & 14 deletions addons/godot-xr-tools/functions/movement_glide.gd
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,17 @@ func physics_movement(delta: float, player_body: XRToolsPlayerBody, disabled: bo

# If wings impulse is active, calculate flapping impulse
if wings_impulse:
# Get head position
var camera_position := _camera_node.global_transform.origin

# Check controllers position relative to head
var left_hand_over_head = camera_position.y < left_position.y + rearm_distance_offset
var right_hand_over_head = camera_position.y < right_position.y + rearm_distance_offset
var cam_local_y := _camera_node.position.y
var left_hand_over_head = cam_local_y < _left_controller.position.y + rearm_distance_offset
var right_hand_over_head = cam_local_y < _right_controller.position.y + rearm_distance_offset
if left_hand_over_head && right_hand_over_head:
flap_armed = true

if flap_armed:
# Get controller local positions
var local_left_position := _left_controller.transform.origin
var local_right_position := _right_controller.transform.origin
var local_left_position := _left_controller.position
var local_right_position := _right_controller.position

# Store last frame controller positions for the first step
if not _has_controller_positions:
Expand All @@ -156,20 +154,20 @@ func physics_movement(delta: float, player_body: XRToolsPlayerBody, disabled: bo
last_local_left_position = local_left_position
last_local_right_position = local_right_position

# If not falling, then not gliding
var vertical_velocity := player_body.velocity.dot(player_body.up_gravity_vector)
vertical_velocity += wings_impulse_velocity
if vertical_velocity >= glide_min_fall_speed && wings_impulse_velocity == 0.0:
_set_gliding(false)
return

# Calculate global left to right controller vector
var left_to_right := right_position - left_position

if turn_with_roll:
var angle = -left_to_right.dot(player_body.up_player_vector)
player_body.rotate_player(roll_turn_speed * delta * angle)

# If not falling, then not gliding
var vertical_velocity := player_body.velocity.dot(player_body.up_gravity_vector)
vertical_velocity += wings_impulse_velocity
if vertical_velocity >= glide_min_fall_speed && wings_impulse_velocity == 0.0:
_set_gliding(false)
return

# Set gliding based on hand separation
var separation := left_to_right.length() / XRServer.world_scale
_set_gliding(separation >= glide_detect_distance)
Expand Down
1 change: 1 addition & 0 deletions addons/godot-xr-tools/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func _set_physics_layers() -> void:
ProjectSettings.set("layer_names/3d_physics/layer_5", "Grappling Target")
ProjectSettings.set("layer_names/3d_physics/layer_17", "Held Objects")
ProjectSettings.set("layer_names/3d_physics/layer_18", "Player Hands")
ProjectSettings.set("layer_names/3d_physics/layer_19", "Grab Handles")
ProjectSettings.set("layer_names/3d_physics/layer_20", "Player Body")
ProjectSettings.set("layer_names/3d_physics/layer_21", "Pointable Objects")
ProjectSettings.set("layer_names/3d_physics/layer_22", "Hand Pose Areas")
Expand Down
3 changes: 1 addition & 2 deletions scenes/sphere_world_demo/objects/tower.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ material = ExtResource("2")
size = Vector3(3, 8, 3)

[node name="Tower" instance=ExtResource("1")]
collision_layer = 2
collision_mask = 0
collision_layer = 262161

[node name="CollisionShape3D" parent="." index="0"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4, 0)
Expand Down
7 changes: 4 additions & 3 deletions scenes/sphere_world_demo/sphere_world_demo.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[gd_scene load_steps=27 format=3 uid="uid://b5o25nkvyv8ho"]
[gd_scene load_steps=28 format=3 uid="uid://b5o25nkvyv8ho"]

[ext_resource type="PackedScene" uid="uid://qbmx03iibuuu" path="res://addons/godot-xr-tools/staging/scene_base.tscn" id="1"]
[ext_resource type="Material" path="res://assets/wahooney.itch.io/green_grid_triplanar.tres" id="2"]
[ext_resource type="PackedScene" uid="uid://diyu06cw06syv" path="res://addons/godot-xr-tools/player/player_body.tscn" id="3"]
[ext_resource type="PackedScene" uid="uid://bx1xdisoqo1f6" path="res://addons/godot-xr-tools/hands/scenes/lowpoly/left_tac_glove_low.tscn" id="4"]
[ext_resource type="Material" uid="uid://p0q2df2dmy62" path="res://addons/godot-xr-tools/hands/materials/ghost_hand.tres" id="4_3wr22"]
[ext_resource type="PackedScene" uid="uid://bl2nuu3qhlb5k" path="res://addons/godot-xr-tools/functions/movement_direct.tscn" id="5"]
[ext_resource type="PackedScene" uid="uid://drs4eeq721ojn" path="res://addons/godot-xr-tools/functions/movement_sprint.tscn" id="6"]
[ext_resource type="PackedScene" uid="uid://c2q5phg8w08o" path="res://addons/godot-xr-tools/functions/movement_jump.tscn" id="7"]
Expand Down Expand Up @@ -42,9 +43,9 @@ environment = ExtResource("19")
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 50, 0)

[node name="LeftHand" parent="XROrigin3D/LeftHand" index="0" instance=ExtResource("4")]
hand_material_override = ExtResource("4_3wr22")

[node name="FunctionPickup" parent="XROrigin3D/LeftHand" index="1" instance=ExtResource("8")]
grab_collision_mask = 6
ranged_enable = false

[node name="MovementDirect" parent="XROrigin3D/LeftHand" index="2" instance=ExtResource("5")]
Expand All @@ -59,9 +60,9 @@ jump_button_action = "ax_button"
crouch_button_action = "by_button"

[node name="RightHand" parent="XROrigin3D/RightHand" index="0" instance=ExtResource("10")]
hand_material_override = ExtResource("4_3wr22")

[node name="FunctionPickup" parent="XROrigin3D/RightHand" index="1" instance=ExtResource("8")]
grab_collision_mask = 6
ranged_enable = false

[node name="MovementDirect" parent="XROrigin3D/RightHand" index="2" instance=ExtResource("5")]
Expand Down
30 changes: 15 additions & 15 deletions scenes/sprinting_demo/objects/climbing_handle.tscn
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=5 format=3 uid="uid://bfjkswl3pu87m"]

[ext_resource path="res://assets/wahooney.itch.io/blue_grid.tres" type="Material" id=1]
[ext_resource path="res://addons/godot-xr-tools/objects/climbable.gd" type="Script" id=2]
[ext_resource type="Material" path="res://assets/wahooney.itch.io/blue_grid.tres" id="1"]
[ext_resource type="PackedScene" uid="uid://cjyilbm4ucc7s" path="res://addons/godot-xr-tools/objects/climbable.tscn" id="1_4eqd4"]

[sub_resource type="CubeMesh" id=1]
material = ExtResource( 1 )
size = Vector3( 0.1, 0.5, 0.5 )
[sub_resource type="BoxMesh" id="1"]
material = ExtResource("1")
size = Vector3(0.1, 0.5, 0.5)

[sub_resource type="BoxShape" id=2]
extents = Vector3( 0.05, 0.25, 0.25 )
[sub_resource type="BoxShape3D" id="2"]
size = Vector3(0.1, 0.5, 0.5)

[node name="ClimbingHandle" type="Spatial"]
[node name="ClimbingHandle" type="Node3D"]

[node name="StaticBody" type="StaticBody" parent="."]
script = ExtResource( 2 )
[node name="Climbable" parent="." instance=ExtResource("1_4eqd4")]

[node name="MeshInstance" type="MeshInstance" parent="StaticBody"]
mesh = SubResource( 1 )
[node name="MeshInstance" type="MeshInstance3D" parent="Climbable"]
mesh = SubResource("1")
skeleton = NodePath("")

[node name="CollisionShape" type="CollisionShape" parent="StaticBody"]
shape = SubResource( 2 )
[node name="CollisionShape" type="CollisionShape3D" parent="Climbable"]
shape = SubResource("2")

0 comments on commit ba5641f

Please sign in to comment.