-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add OpenXR demo project showing off local reference space #1012
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
base: master
Are you sure you want to change the base?
Conversation
For those who are interested in this, recording of the stream in which I build the first part of this demo: https://youtube.com/live/eWpNwrPTiqw |
d256e73
to
d1206e9
Compare
I've added a Gokart model from sketchfab that is CC-BY-4.0, hopefully that is acceptable here, else I'll need to look into another one. This also has a little display on the steering wheel that we've used to display FPS and velocity information. Nice little touch. Also added a polyhaven skytexture. |
xr/openxr_vehicle_movement/assets/uv.jpg Maybe you could add a separate |
d6df5e8
to
98483a9
Compare
I ended up removing it as I only used it temporarily. |
d77ba52
to
3a74158
Compare
3a74158
to
670de95
Compare
extends CanvasLayer | ||
|
||
func set_velocity(p_velocity : float): | ||
%Velocity.text = "Velocity: %0.2f kmph (%0.2f m/s)" % [ p_velocity * 3.6, p_velocity ] | ||
|
||
# Called every frame. 'delta' is the elapsed time since the previous frame. | ||
func _process(delta): |
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.
Please follow the GDScript style guide, and use static typing, for all code in the demos.
We should fix all warnings before merging, such as by adding _
before delta
.
Kilometers per hour is km/h
not kmph
. Also, I'd argue we should use meters per second as the primary (or only) unit, since it's the unit of velocity Godot users are working with in code.
extends CanvasLayer | |
func set_velocity(p_velocity : float): | |
%Velocity.text = "Velocity: %0.2f kmph (%0.2f m/s)" % [ p_velocity * 3.6, p_velocity ] | |
# Called every frame. 'delta' is the elapsed time since the previous frame. | |
func _process(delta): | |
extends CanvasLayer | |
func set_velocity(p_velocity: float) -> void: | |
%Velocity.text = "Velocity: %0.2f m/s (%0.2f km/h)" % [p_velocity, p_velocity * 3.6] | |
func _process(_delta: float) -> void: |
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.
All file names should use snake_case
, only composed of lowercase, underscores, dots, and maybe numbers.
] | ||
} | ||
}, | ||
"name": "Material.004" |
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.
We should ideally clean up the original 3D model file, at least such that it will have human-readable names for its parts, but we could go even further, such as including physics in the model. I could work on this but it's not a high priority for me.
# Called every frame. 'delta' is the elapsed time since the previous frame. | ||
func _process(delta): |
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.
# Called every frame. 'delta' is the elapsed time since the previous frame. | |
func _process(delta): | |
func _process(delta): |
@@ -0,0 +1,8 @@ | |||
extends CanvasLayer | |||
|
|||
func set_velocity(p_velocity : float): |
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.
func set_velocity(p_velocity : float): | |
func set_velocity(p_velocity: float): |
|
||
## Input and the action map | ||
|
||
This demo uses Godots standard input map to allow for keyboard and gamepad input. |
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.
This demo uses Godots standard input map to allow for keyboard and gamepad input. | |
This demo uses Godot's standard input map to allow for keyboard and gamepad input. |
There is also an action map setup so you can use the XR controllers. | ||
Move your hands close enough to the steering wheel so they grab the wheel, | ||
this will disable traditional input and enable you to control the steering wheel with your hands. | ||
You can then use the trigger on the left controller to accellerate, and the trigger on the right controller to break. |
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.
You can then use the trigger on the left controller to accellerate, and the trigger on the right controller to break. | |
You can then use the trigger on the left controller to accelerate, and the trigger on the right controller to break. |
$Label3D.visible = false | ||
set_process(false) | ||
else: | ||
# Update fade |
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.
# Update fade | |
# Update fade. |
For all
if is_inside_tree(): | ||
_update_tires() | ||
|
||
func _update_tires(): |
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.
func _update_tires(): | |
func _update_tires(): |
if material: | ||
material.set_shader_parameter("albedo_texture", %InfoViewport.get_texture()) | ||
|
||
# Called every frame. 'delta' is the elapsed time since the previous frame. |
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.
# Called every frame. 'delta' is the elapsed time since the previous frame. | |
# Called every frame. 'delta' is the elapsed time since the previous frame. |
|
||
# Called every frame. 'delta' is the elapsed time since the previous frame. | ||
func _process(delta): | ||
# Check steering |
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.
# Check steering | |
# Check steering. |
For all
steering_input = 1.0 | ||
else: | ||
steering_input = Input.get_axis("turn_left", "turn_right") | ||
steering = steering_input * -MAX_STEERING_ANGLE |
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.
steering = steering_input * -MAX_STEERING_ANGLE | |
steering = steering_input * -MAX_STEERING_ANGLE |
elif just_pressed_accel: | ||
reverse = false | ||
|
||
if !reverse: |
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.
if !reverse: | |
if not reverse: |
This demo shows off how to create a vehicle centric XR game using OpenXR.
The basic idea is a simple go-kart race game.
Important here is the use of the "local" reference space.
It also shows mixing traditional inputs (keyboard/gamepad/steering wheel) with XR input.
If the player uses their controllers and holds them near the steering wheel, they will snap into place and the player will be able to turn the wheel. The triggers on the controller are used to accelerate (right controller) and brake (left controller)