init
This commit is contained in:
62
addons/godot-xr-tools/functions/movement_jump.gd
Normal file
62
addons/godot-xr-tools/functions/movement_jump.gd
Normal file
@@ -0,0 +1,62 @@
|
||||
@tool
|
||||
class_name XRToolsMovementJump
|
||||
extends XRToolsMovementProvider
|
||||
|
||||
|
||||
## XR Tools Movement Provider for Jumping
|
||||
##
|
||||
## This script provides jumping mechanics for the player. This script works
|
||||
## with the [XRToolsPlayerBody] attached to the players [XROrigin3D].
|
||||
##
|
||||
## The player enables jumping by attaching an [XRToolsMovementJump] as a
|
||||
## child of the appropriate [XRController3D], then configuring the jump button
|
||||
## and jump velocity.
|
||||
|
||||
|
||||
## Movement provider order
|
||||
@export var order : int = 20
|
||||
|
||||
## Button to trigger jump
|
||||
@export var jump_button_action : String = "trigger_click"
|
||||
|
||||
|
||||
# Node references
|
||||
var _controller : XRController3D
|
||||
|
||||
|
||||
# Add support for is_xr_class on XRTools classes
|
||||
func is_xr_class(xr_name: String) -> bool:
|
||||
return xr_name == "XRToolsMovementJump" or super(xr_name)
|
||||
|
||||
|
||||
# Called when our node is added to our scene tree
|
||||
func _enter_tree():
|
||||
_controller = XRHelpers.get_xr_controller(self)
|
||||
|
||||
|
||||
# Called when our node is removed from our scene tree
|
||||
func _exit_tree():
|
||||
_controller = null
|
||||
|
||||
|
||||
# Perform jump movement
|
||||
func physics_movement(_delta: float, player_body: XRToolsPlayerBody, _disabled: bool):
|
||||
# Skip if the jump controller isn't active
|
||||
if not _controller or not _controller.get_is_active():
|
||||
return
|
||||
|
||||
# Request jump if the button is pressed
|
||||
if _controller.is_button_pressed(jump_button_action):
|
||||
player_body.request_jump()
|
||||
|
||||
|
||||
# This method verifies the movement provider has a valid configuration.
|
||||
func _get_configuration_warnings() -> PackedStringArray:
|
||||
var warnings := super()
|
||||
|
||||
# Check the controller node
|
||||
if not XRHelpers.get_xr_controller(self):
|
||||
warnings.append("This node must be within a branch of an XRController3D node")
|
||||
|
||||
# Return warnings
|
||||
return warnings
|
||||
Reference in New Issue
Block a user