-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add page on controller-specific features (currently just LED) #11533
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a08954a
Add page on controller-specific features (currently just LED)
Meorge da17380
Update tutorials/inputs/controller_features.rst [no ci]
Meorge 9a32625
Add warning about supported platforms and remove PR link in comment
Meorge 472007f
Update tutorials/inputs/controller_features.rst
Meorge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,94 @@ | ||
| .. _doc_controller_features: | ||
|
|
||
| Controller features | ||
| =================== | ||
|
|
||
| Godot supports controller-specific features that can further enhance the gameplay | ||
| experience. This page describes these features, how existing games have used them, | ||
| and how you can get started with them in Godot. | ||
|
|
||
| .. warning:: | ||
|
|
||
| These controller features are currently only supported on Windows, macOS, and Linux. | ||
|
|
||
|
|
||
| .. warning:: | ||
|
|
||
| Unless you specifically advertise your game as requiring specific controllers, | ||
| remember that there is no guarantee that players will have a controller with | ||
| any given features. | ||
|
|
||
| As a result, we suggest using these features to enhance the gameplay experience | ||
| for players whose controllers support them, without detracting from those who | ||
| don't have controllers. | ||
|
|
||
|
|
||
| LED color | ||
| --------- | ||
|
|
||
| Games can use the LED lights on certain controllers to subtly complement the on-screen gameplay by | ||
| providing some matching visuals in the player's hands. Here are some notable examples: | ||
|
|
||
| - In *Hades*, the color of the light matches the god you're receiving a boon from. | ||
| - In *Resident Evil 2*, the color of the light indicates your health (green for full, yellow for medium, red for low). | ||
| - In *Star Wars Jedi: Fallen Order*, the color of the light matches your lightsaber's color. | ||
|
|
||
| Use the method :ref:`Input.set_joy_light()<class_Input_method_set_joy_light>` to set the color | ||
| of a given controller's LEDs. | ||
|
|
||
| To determine if a given controller supports setting LED lights, use the :ref:`Input.has_joy_light()<class_Input_method_has_joy_light>` | ||
| method. The PlayStation DualShock and DualSense controllers are known to support LED lights. | ||
|
|
||
| The following ``_process()`` method sets the LED color according to the currently pressed button, | ||
| and turns it off if no button is being pressed: | ||
|
|
||
| .. code-block:: | ||
|
|
||
| func _process(_delta): | ||
| var color := Color.BLACK | ||
|
|
||
| if Input.is_joy_button_pressed(0, JOY_BUTTON_A): | ||
| color = Color.BLUE | ||
| elif Input.is_joy_button_pressed(0, JOY_BUTTON_X): | ||
| color = Color.MAGENTA | ||
| elif Input.is_joy_button_pressed(0, JOY_BUTTON_B): | ||
| color = Color.RED | ||
| elif Input.is_joy_button_pressed(0, JOY_BUTTON_Y): | ||
| color = Color.GREEN | ||
|
|
||
| Input.set_joy_light(0, color) | ||
|
|
||
|
|
||
| The following example smoothly fades the LED through hues in a loop: | ||
|
|
||
| .. code-block:: | ||
|
|
||
| var hue = 0.0 | ||
|
|
||
| func _process(delta): | ||
| var col = Color.from_hsv(hue, 1.0, 1.0) | ||
| Input.set_joy_light(0, col) | ||
| hue += delta * 0.1 | ||
|
|
||
| The following example makes the LED blink red three times when the south button (Cross/X on PlayStation controllers) is pressed: | ||
|
|
||
| .. code-block:: | ||
|
|
||
| var blink_tween: Tween = null | ||
|
|
||
| func _process(_delta): | ||
| var ready_to_blink = not blink_tween or not blink_tween.is_running() | ||
| if Input.is_joy_button_pressed(0, JOY_BUTTON_A) and ready_to_blink: | ||
| do_blink() | ||
|
|
||
| func do_blink(): | ||
| if blink_tween: | ||
| blink_tween.kill() | ||
|
|
||
| blink_tween = create_tween() | ||
| blink_tween.tween_callback(func(): Input.set_joy_light(0, Color.RED)) | ||
| blink_tween.tween_interval(0.2) | ||
| blink_tween.tween_callback(func(): Input.set_joy_light(0, Color.BLACK)) | ||
| blink_tween.tween_interval(0.2) | ||
| blink_tween.set_loops(3) | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be worth re-wording this to just be explicit that only LED features are supported for now. I expect that to change in the future, but when 4.6 releases it's going to be the only thing available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get what you're suggesting here, but I'm not sure at the moment how to rephrase it so that the page overall doesn't sound like it should be entirely dedicated to the LED feature. For example, if we changed
to
then as a reader, I would probably wonder why the page as a whole isn't titled something like "LEDs on controllers" instead of the more generic "Controller features". Given that the "LED color" section is the only one on the page, IMO it's self-explanatory that it's the only supported feature for now.
I suppose we could add a sentence saying something like
However, that seems like a bit deeper of a dive into Godot's development than the manual tends to do.