Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

World-scale fixes for movement providers #155

Merged
merged 1 commit into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions addons/godot-xr-tools/VERSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
- Added crouch movement provider
- Added example fall damage detection
- Added moving platform support to player body
- Fixed player height-clamping to work in player-units
- Fixed glide T-pose detection to work in player-units
- Fixed jump detection to work in player-units

# 2.4.1
- Fixed grab distance
Expand Down
4 changes: 2 additions & 2 deletions addons/godot-xr-tools/assets/PlayerBody.gd
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,8 @@ func _update_body_under_camera():
# Calculate the player height based on the camera position in the origin and the calibration
var player_height := clamp(
camera_node.transform.origin.y + player_head_height + player_height_offset,
player_height_min,
player_height_max)
player_height_min * ARVRServer.world_scale,
player_height_max * ARVRServer.world_scale)

# Allow forced overriding of height
if _player_height_override >= 0.0:
Expand Down
3 changes: 2 additions & 1 deletion addons/godot-xr-tools/functions/Function_Glide_movement.gd
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ func physics_movement(delta: float, player_body: PlayerBody, disabled: bool):
var left_to_right := (right_position - left_position) * HORIZONTAL

# Set gliding based on hand separation
_set_gliding(left_to_right.length() >= glide_detect_distance)
var separation := left_to_right.length() / ARVRServer.world_scale
_set_gliding(separation >= glide_detect_distance)

# Skip if not gliding
if !is_active:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ func _detect_body_jump(delta: float, player_body: PlayerBody) -> void:
if abs(camera_vel) < 0.001:
return;

# Correct for ARVR world-scale (convert to player units)
camera_vel /= ARVRServer.world_scale

# Clamp the camera instantaneous velocity to +/- 2x the jump threshold
camera_vel = clamp(camera_vel, -2.0 * body_jump_threshold, 2.0 * body_jump_threshold)

Expand Down Expand Up @@ -144,6 +147,10 @@ func _detect_arms_jump(delta: float, player_body: PlayerBody) -> void:
if abs(controller_left_vel) <= 0.001 and abs(controller_right_vel) <= 0.001:
return

# Correct for ARVR world-scale (convert to player units)
controller_left_vel /= ARVRServer.world_scale
controller_right_vel /= ARVRServer.world_scale

# Clamp the controller instantaneous velocity to +/- 2x the jump threshold
controller_left_vel = clamp(controller_left_vel, -2.0 * arms_jump_threshold, 2.0 * arms_jump_threshold)
controller_right_vel = clamp(controller_right_vel, -2.0 * arms_jump_threshold, 2.0 * arms_jump_threshold)
Expand Down