-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sprinting/jumping, Fix camera responsiveness
About the fix: Camera would sometimes get sent to negative infinity if the slope was too high. Also made camera smooth less when falling down stairs to look more natural.
- Loading branch information
Showing
12 changed files
with
636 additions
and
173 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,42 +1,32 @@ | ||
extends Spatial | ||
|
||
""" | ||
Additional script to handle interacting-with and shooting physics bodies. | ||
Optional script to handle shooting physics bodies and toggling fullscreen. | ||
This template does not include damaging targets or calling functions on interactive elements. | ||
This template does not include how to damage targets, just how to recognize them. | ||
All player movement (the meat of this template) is on the KinematicBody child. | ||
""" | ||
|
||
onready var player_body: KinematicBody = $Body | ||
onready var head_camera: Camera = $Body/HeadCamera | ||
onready var cursor_ray: RayCast = $Body/HeadCamera/CursorRay | ||
onready var shoot_ray: RayCast = $Body/HeadCamera/ShootRay | ||
|
||
func _unhandled_input(event): | ||
# Requires "shoot" and "interact" setup in Project Settings -> Input Map. | ||
if event.is_action_pressed("interact"): | ||
_interact(true) | ||
if event.is_action_released("interact"): | ||
_interact(false) | ||
func _unhandled_input(event: InputEvent) -> void: | ||
if player_body.can_handle_input and event.is_action_pressed("shoot"): | ||
_shoot() | ||
shoot() | ||
if event.is_action_released("toggle_fullscreen"): | ||
OS.window_fullscreen = not OS.window_fullscreen | ||
|
||
## Can be called to pause recieving the player's inputs, without pausing physics or the SceneTree. | ||
## Pauses the player's ability to recieve inputs. Doesn't pause physics or the SceneTree. | ||
func set_movement_input(_true: bool) -> void: | ||
player_body.can_handle_input = _true | ||
|
||
# Private functions. Simple games shouldn't need to access these in other scripts. Advanced games | ||
# should move these functions into a new child node/script to handle more complex interactions. | ||
|
||
func _interact(is_pressed: bool) -> void: | ||
if not cursor_ray.is_colliding(): | ||
return | ||
var body = cursor_ray.get_collider() | ||
print_debug(body) # replace with code to handle interactable bodies | ||
|
||
func _shoot() -> void: | ||
func shoot() -> void: | ||
if shoot_ray.is_colliding(): | ||
var body = shoot_ray.get_collider() | ||
var body: PhysicsBody = shoot_ray.get_collider() | ||
if body is StaticBody: | ||
return # or process shooting the world here | ||
return # handle shooting the world | ||
else: | ||
print_debug(body) # replace with code to handle shootable bodies | ||
print_debug(body) # handle shooting moving bodies |
This file contains 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.