Skip to content

Commit

Permalink
* movement in 1st person view is only accepted if vr_mode is disabled
Browse files Browse the repository at this point in the history
* added a draft for a symbol of the player position in 3rd person view
* but currently does not work
  • Loading branch information
chrisgraf committed Jul 11, 2019
1 parent 44b8ef2 commit 12fd124
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 33 deletions.
13 changes: 11 additions & 2 deletions Perspectives/PC/FirstPersonPC.tscn
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
[gd_scene load_steps=7 format=2]
[gd_scene load_steps=8 format=2]

[ext_resource path="res://Perspectives/PC/PlayerController.gd" type="Script" id=1]
[ext_resource path="res://Perspectives/PC/SettingsCamera.gd" type="Script" id=2]
[ext_resource path="res://Perspectives/PC/MousePoint.tscn" type="PackedScene" id=3]
[ext_resource path="res://Perspectives/PC/Minimap/MinimapIcon.tscn" type="PackedScene" id=4]
[ext_resource path="res://Resources/Images/UI/MapIcons/MapCursor.png" type="Texture" id=5]
[ext_resource path="res://Resources/Images/UI/MapIcons/red_dot.png" type="Texture" id=6]

[sub_resource type="CapsuleShape" id=1]

Expand Down Expand Up @@ -35,7 +36,15 @@ transform = Transform( 1.00002, 0, 0, 0, 1, 0, 0, 0, 1.00002, 0, 0, 0 )
icon = ExtResource( 5 )
rotate = true

[node name="PlayerMarker" type="Sprite3D" parent="Head"]
layers = 4
opacity = 0.7
pixel_size = 1.0
axis = 1
texture = ExtResource( 6 )

[node name="CollisionShape" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 1.77636e-15, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 1.65595, 0 )
transform = Transform( 1, 0, 1.77636e-015, 0, -4.37114e-008, -1, 0, 1, -4.37114e-008, 0, 1.65595, 0 )
shape = SubResource( 1 )
disabled = true

2 changes: 1 addition & 1 deletion Perspectives/PC/Minimap/MinimapIcon.gd
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ func update_icon(var texture):

icon_sprite.texture = texture

icon_sprite.modulate = color_modulate
icon_sprite.modulate = color_modulate
73 changes: 45 additions & 28 deletions Perspectives/PC/PlayerController.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var camera_angle = 0
var velocity = Vector3()
var dragging : bool = false
var rotating : bool = false
var _vr_mode : bool = false

var walking = Settings.get_setting("player", "start-walking-enabled")

Expand All @@ -24,6 +25,11 @@ onready var head = get_node("Head")
onready var camera = head.get_node("Camera")


func _ready():
GlobalSignal.connect("vr_enable", self, "_set_vr_mode", [true])
GlobalSignal.connect("vr_disable", self, "_set_vr_mode", [false])


# To prevent floating point errors, the player.translation does not reflect the player's
# actual position in the whole world. This function returns the true world position of
# the player (in webmercator meters) as integers.
Expand All @@ -37,42 +43,48 @@ func get_look_direction():


func _physics_process(delta):
fly(delta)
PlayerInfo.update_player_look_direction(get_look_direction())

# only change position if vr_mode is disabled
if not _vr_mode:
fly(delta)
PlayerInfo.update_player_look_direction(get_look_direction())


func _input(event):

# checks if the mouse is over the associated viewport
# FIXME: if the viewport is covered by another viewport the event is still propagated down
# TODO: input could be generalized in AbstractPlayer?
if get_viewport().get_visible_rect().has_point(get_viewport().get_mouse_position()):
# only accept input if vr mode is disabled
if not _vr_mode:

if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT:
if event.pressed:
dragging = true
else:
dragging = false
elif event.button_index == BUTTON_RIGHT:
if event.pressed:
rotating = true
else:
rotating = false

# Rotate the camera if the event is mouse motion and the mouse is currently captured or right mouse button is pressed
if event is InputEventMouseMotion and (Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED or rotating):
head.rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))
# checks if the mouse is over the associated viewport
# FIXME: if the viewport is covered by another viewport the event is still propagated down
# TODO: input could be generalized in AbstractPlayer?
if get_viewport().get_visible_rect().has_point(get_viewport().get_mouse_position()):

var change = -event.relative.y * mouse_sensitivity
if event is InputEventMouseButton:
if event.button_index == BUTTON_LEFT:
if event.pressed:
dragging = true
else:
dragging = false
elif event.button_index == BUTTON_RIGHT:
if event.pressed:
rotating = true
else:
rotating = false

if change + camera_angle < 90 and change + camera_angle > -90:
camera.rotate_x(deg2rad(change))
camera_angle += change
# Rotate the camera if the event is mouse motion and the mouse is currently captured or right mouse button is pressed
if event is InputEventMouseMotion and (Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED or rotating):
head.rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))

elif event.is_action_pressed("pc_toggle_walk"):
walking = not walking

var change = -event.relative.y * mouse_sensitivity

if change + camera_angle < 90 and change + camera_angle > -90:
camera.rotate_x(deg2rad(change))
camera_angle += change

elif event.is_action_pressed("pc_toggle_walk"):
walking = not walking


func fly(delta):
# reset the direction of the player
Expand Down Expand Up @@ -120,3 +132,8 @@ func fly(delta):
func switch_follow_mode():
PlayerInfo.update_player_pos(translation)
PlayerInfo.is_follow_enabled = !PlayerInfo.is_follow_enabled


func _set_vr_mode(vr_mode):
logger.info("vr mode set to %s " % [vr_mode])
_vr_mode = vr_mode
3 changes: 2 additions & 1 deletion Perspectives/PC/ThirdPersonPC.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ collision_mask = 16385
shape = SubResource( 1 )

[node name="MinimapIcon" parent="." instance=ExtResource( 4 )]
transform = Transform( 1, 0, 0, 0, 1, 5.36442e-07, 0, -5.36442e-07, 1, 0, 0, 0 )
transform = Transform( 1, 0, 0, 0, 1, 5.36442e-007, 0, -5.36442e-007, 1, 0, 0, 0 )
icon = ExtResource( 5 )
color_modulate = Color( 0.25, 0.25, 0.25, 1 )
rotate = true

2 changes: 1 addition & 1 deletion Perspectives/WireframeSupportingViewport.gd
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ func _on_wireframe_toggle(toggled):
if toggled:
debug_draw = DEBUG_DRAW_WIREFRAME
else:
debug_draw = DEBUG_DRAW_DISABLED
debug_draw = DEBUG_DRAW_DISABLED

0 comments on commit 12fd124

Please sign in to comment.