mirror of
https://github.com/Relintai/broken_seals.git
synced 2024-11-13 20:47:19 +01:00
Moved movement handling code from Player.gd to a new gdscript that is on the player's body. Also update everything to the latest to grab the changes to ESS.
This commit is contained in:
parent
1e3e65bd73
commit
b30a02f7b8
2
HEADS
2
HEADS
@ -1 +1 @@
|
||||
{"engine": {"3.2": "cb1366f006dfc9904083e8fc6fa23e271bc39e39", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "9d946f1623b9cb57b2e1d9681ac3b7f7e7b746d4"}, "entity_spell_system": {"master": "da2a116426e14182fcb571065d8b13d0cb1cf05c"}, "ui_extensions": {"master": "6fe4f69fea8d71043b08d959b8085404c9c4fe47"}, "voxelman": {"master": "23c4321d71927a0e2d08b5d19fc4c5bb8242e7d2"}, "texture_packer": {"master": "b29b499adf570aa7f85af69ef080ff0d5e04afae"}, "fastnoise": {"master": "d0e3f1c759332cf0d9a5d7e0e71d0b0278310651"}, "mesh_data_resource": {"master": "4ee946963a16bbfdb4dbb5df52134d22aa168041"}, "procedural_animations": {"master": "9ae56c17230ba9c6160777650b2b89eecdc8df9e"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "fast_quadratic_mesh_simplifier": {"master": "f6d3d65cc6ce4dddfc68054164feec1f612ecd1f"}, "props": {"master": "b2bcb5ea6469b19298cd849c1232ddb5ad26f71c"}}
|
||||
{"engine": {"3.2": "ed27b7e6b973eb6be6fdac4439e99a1907b9cb58", "master": "8c73e813134001e575b6f59e3b0100471c007410"}, "world_generator": {"master": "97f10512f8832394389e1109154b8af34a2ef2c6"}, "entity_spell_system": {"master": "677f138a462b248d45b679a66d0b4cd3ed886ef8"}, "ui_extensions": {"master": "6fe4f69fea8d71043b08d959b8085404c9c4fe47"}, "voxelman": {"master": "af0c4d6586fa4dd7364280df6c4a0a768d9436da"}, "texture_packer": {"master": "b29b499adf570aa7f85af69ef080ff0d5e04afae"}, "fastnoise": {"master": "d0e3f1c759332cf0d9a5d7e0e71d0b0278310651"}, "mesh_data_resource": {"master": "4ee946963a16bbfdb4dbb5df52134d22aa168041"}, "procedural_animations": {"master": "9ae56c17230ba9c6160777650b2b89eecdc8df9e"}, "ess_data": {"master": "3bd637fdd3304b64a18287a49a6b7387acf2f5de"}, "fast_quadratic_mesh_simplifier": {"master": "f6d3d65cc6ce4dddfc68054164feec1f612ecd1f"}, "props": {"master": "b2bcb5ea6469b19298cd849c1232ddb5ad26f71c"}}
|
File diff suppressed because one or more lines are too long
434
game/player/Body.gd
Normal file
434
game/player/Body.gd
Normal file
@ -0,0 +1,434 @@
|
||||
# Copyright Péter Magyar relintai@gmail.com
|
||||
# MIT License, functionality from this class needs to be protable to the entity spell system
|
||||
|
||||
# Copyright (c) 2019-2020 Péter Magyar
|
||||
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
extends KinematicBody
|
||||
|
||||
export(float) var MOUSE_SENSITIVITY : float = 0.05
|
||||
export(String) var world_path : String = "../.."
|
||||
export(NodePath) var model_path : NodePath = "Rotation_Helper/Model"
|
||||
export(NodePath) var character_skeleton_path : NodePath = "Rotation_Helper/Model/character"
|
||||
|
||||
const ray_length = 1000
|
||||
const ACCEL : float = 100.0
|
||||
const DEACCEL : float = 100.0
|
||||
const GRAVITY : float = -24.8
|
||||
const JUMP_SPEED : float = 3.8
|
||||
const MAX_SLOPE_ANGLE : float = 40.0
|
||||
const MOUSE_TARGET_MAX_OFFSET : int = 10
|
||||
|
||||
var _on : bool = false
|
||||
|
||||
var y_rot : float = 0.0
|
||||
|
||||
var vel : Vector3 = Vector3()
|
||||
var dir : Vector3 = Vector3()
|
||||
|
||||
var input_dir : Vector2 = Vector2()
|
||||
var mouse_dir : Vector2 = Vector2()
|
||||
var mouse_move_dir : Vector2 = Vector2()
|
||||
var mouse_left_down : bool = false
|
||||
var mouse_right_down : bool = false
|
||||
var touchpad_dir : Vector2 = Vector2()
|
||||
var mouse_down_delta : Vector2 = Vector2()
|
||||
var queued_camera_rotaions : Vector2 = Vector2()
|
||||
|
||||
var key_left : bool = false
|
||||
var key_right : bool = false
|
||||
var key_up : bool = false
|
||||
var key_down : bool = false
|
||||
|
||||
var cursor_grabbed : bool = false
|
||||
var last_cursor_pos : Vector2 = Vector2()
|
||||
var mouse_down_pos : Vector2 = Vector2()
|
||||
var total_down_mouse_delta : Vector2 = Vector2()
|
||||
|
||||
var camera : Camera
|
||||
var camera_pivot : Spatial
|
||||
|
||||
var animation_tree : AnimationTree
|
||||
var anim_node_state_machine : AnimationNodeStateMachinePlayback = null
|
||||
var animation_run : bool = false
|
||||
|
||||
var moving : bool = false
|
||||
var casting_anim : bool = false
|
||||
|
||||
var last_mouse_over : Entity = null
|
||||
|
||||
var world : VoxelWorld = null
|
||||
|
||||
var entity : Entity
|
||||
var model_rotation_node : Spatial
|
||||
var character_skeleton : CharacterSkeleton3D
|
||||
|
||||
func _ready() -> void:
|
||||
camera = $CameraPivot/Camera as Camera
|
||||
camera_pivot = $CameraPivot as Spatial
|
||||
|
||||
model_rotation_node = get_node(model_path)
|
||||
character_skeleton = get_node(character_skeleton_path)
|
||||
entity = get_node("..")
|
||||
entity.connect("ccast_started", self, "_con_cast_started")
|
||||
entity.connect("ccast_failed", self, "_con_cast_failed")
|
||||
entity.connect("ccast_finished", self, "_con_cast_finished")
|
||||
entity.connect("cspell_cast_success", self, "_con_spell_cast_success")
|
||||
|
||||
animation_tree = character_skeleton.get_animation_tree()
|
||||
|
||||
if animation_tree != null:
|
||||
anim_node_state_machine = animation_tree["parameters/playback"]
|
||||
|
||||
func _enter_tree():
|
||||
world = get_node(world_path) as VoxelWorld
|
||||
set_physics_process(true)
|
||||
get_parent().connect("isc_controlled_changed", self, "on_c_controlled_changed")
|
||||
|
||||
|
||||
func _physics_process(delta : float) -> void:
|
||||
if not _on:
|
||||
return
|
||||
|
||||
if world.initial_generation:
|
||||
return
|
||||
|
||||
process_input(delta)
|
||||
process_movement(delta)
|
||||
|
||||
func process_input(delta: float) -> void:
|
||||
var key_dir : Vector2 = Vector2()
|
||||
|
||||
if key_up:
|
||||
key_dir.y -= 1
|
||||
if key_down:
|
||||
key_dir.y += 1
|
||||
if key_left:
|
||||
key_dir.x -= 1
|
||||
if key_right:
|
||||
key_dir.x += 1
|
||||
|
||||
input_dir = key_dir + mouse_dir + touchpad_dir + mouse_move_dir
|
||||
|
||||
var state : int = entity.getc_state()
|
||||
|
||||
if state & EntityEnums.ENTITY_STATE_TYPE_FLAG_ROOT != 0 or state & EntityEnums.ENTITY_STATE_TYPE_FLAG_STUN != 0:
|
||||
input_dir = Vector2()
|
||||
return
|
||||
|
||||
var input_length : float = input_dir.length_squared()
|
||||
|
||||
if input_length > 0.1:
|
||||
if anim_node_state_machine != null and not animation_run:
|
||||
anim_node_state_machine.travel("run-loop")
|
||||
animation_run = true
|
||||
|
||||
input_dir = input_dir.normalized()
|
||||
|
||||
animation_tree["parameters/run-loop/blend_position"] = input_dir
|
||||
|
||||
if (input_dir.y < 0.1):
|
||||
model_rotation_node.transform.basis = Basis(Vector3(0, acos(input_dir.x) - PI / 2.0, 0))
|
||||
else:
|
||||
model_rotation_node.transform.basis = Basis()
|
||||
else:
|
||||
if anim_node_state_machine != null and animation_run:
|
||||
anim_node_state_machine.travel("idle-loop")
|
||||
animation_run = false
|
||||
|
||||
if queued_camera_rotaions.length_squared() > 1:
|
||||
camera_pivot.rotate_delta(queued_camera_rotaions.x * 2.0, queued_camera_rotaions.y)
|
||||
queued_camera_rotaions = Vector2()
|
||||
|
||||
if input_length > 0.1:
|
||||
rotate_delta(camera_pivot.get_y_rot())
|
||||
camera_pivot.set_y_rot(0.0)
|
||||
|
||||
func process_movement(delta : float) -> void:
|
||||
var state : int = entity.getc_state()
|
||||
|
||||
if state & EntityEnums.ENTITY_STATE_TYPE_FLAG_ROOT != 0 or state & EntityEnums.ENTITY_STATE_TYPE_FLAG_STUN != 0:
|
||||
moving = false
|
||||
return
|
||||
|
||||
if input_dir.x > 0.1 or input_dir.y > 0.1 or input_dir.x < -0.1 or input_dir.y < -0.1:
|
||||
var forward : Vector3 = Vector3(0, 0, 1).rotated(Vector3(0, 1, 0), deg2rad(y_rot))
|
||||
var right : Vector3 = forward.cross(Vector3(0, 1, 0)) * -input_dir.x
|
||||
forward *= input_dir.y #only potentially make it zero after getting the right vector
|
||||
|
||||
dir = forward
|
||||
dir += right
|
||||
|
||||
if dir.length_squared() > 0.1:
|
||||
dir = dir.normalized()
|
||||
|
||||
moving = true
|
||||
entity.moved()
|
||||
else:
|
||||
dir = Vector3()
|
||||
moving = false
|
||||
|
||||
vel.y += delta * GRAVITY
|
||||
|
||||
var hvel : Vector3 = vel
|
||||
hvel.y = 0
|
||||
|
||||
var target : Vector3 = dir
|
||||
target *= entity.get_speed().ccurrent
|
||||
|
||||
var accel
|
||||
if dir.dot(hvel) > 0:
|
||||
accel = ACCEL
|
||||
else:
|
||||
accel = DEACCEL
|
||||
|
||||
hvel = hvel.linear_interpolate(target, accel * delta) as Vector3
|
||||
vel.x = hvel.x
|
||||
vel.z = hvel.z
|
||||
vel = move_and_slide(vel, Vector3(0,1,0), true, 4, deg2rad(MAX_SLOPE_ANGLE))
|
||||
|
||||
if multiplayer.has_network_peer():
|
||||
if not multiplayer.is_network_server():
|
||||
rpc_id(1, "sset_position", translation, rotation)
|
||||
else:
|
||||
sset_position(translation, rotation)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not cursor_grabbed:
|
||||
set_process_input(false)
|
||||
return
|
||||
|
||||
if event is InputEventMouseMotion and event.device != -1:
|
||||
var s : float = ProjectSettings.get("display/mouse_cursor/sensitivity")
|
||||
|
||||
var relx : float = event.relative.x * s
|
||||
var rely : float = event.relative.y * s
|
||||
|
||||
mouse_down_delta.x += relx
|
||||
mouse_down_delta.y += rely
|
||||
|
||||
total_down_mouse_delta.x += relx
|
||||
total_down_mouse_delta.y += rely
|
||||
|
||||
get_tree().set_input_as_handled()
|
||||
|
||||
if (mouse_right_down or mouse_left_down) and event.device != -1:
|
||||
if mouse_right_down:
|
||||
camera_pivot.rotate_delta(0.0, -event.relative.y)
|
||||
rotate_delta(-event.relative.x)
|
||||
else:
|
||||
camera_pivot.rotate_delta(-relx, -rely)
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventKey:
|
||||
var ievkey : InputEventKey = event as InputEventKey
|
||||
|
||||
if ievkey.scancode == KEY_W:
|
||||
key_up = ievkey.pressed
|
||||
if ievkey.scancode == KEY_S:
|
||||
key_down = ievkey.pressed
|
||||
if ievkey.scancode == KEY_A:
|
||||
key_left = ievkey.pressed
|
||||
if ievkey.scancode == KEY_D:
|
||||
key_right = ievkey.pressed
|
||||
|
||||
if event is InputEventMouseMotion and not (mouse_right_down or mouse_left_down) and event.device != -1:
|
||||
cmouseover(event)
|
||||
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == BUTTON_LEFT and event.device != -1:
|
||||
mouse_left_down = event.pressed
|
||||
|
||||
if mouse_left_down:
|
||||
mouse_down_delta = Vector2()
|
||||
mouse_down_pos = event.position
|
||||
|
||||
if event.button_index == BUTTON_RIGHT and event.device != -1:
|
||||
mouse_right_down = event.pressed
|
||||
|
||||
if mouse_right_down:
|
||||
rotate_delta(camera_pivot.get_y_rot())
|
||||
camera_pivot.set_y_rot(0.0)
|
||||
|
||||
if mouse_left_down and mouse_right_down:
|
||||
mouse_move_dir.y = -1
|
||||
else:
|
||||
mouse_move_dir.y = 0
|
||||
|
||||
if event.is_pressed() and event.device != -1:
|
||||
if event.button_index == BUTTON_WHEEL_UP:
|
||||
camera_pivot.camera_distance_set_delta(-0.2)
|
||||
if event.button_index == BUTTON_WHEEL_DOWN:
|
||||
camera_pivot.camera_distance_set_delta(0.2)
|
||||
|
||||
if not event.pressed and event.button_index == BUTTON_LEFT and event.device != -1:
|
||||
if mouse_down_delta.length() < MOUSE_TARGET_MAX_OFFSET:
|
||||
target(event.position)
|
||||
|
||||
if event is InputEventScreenTouch and event.pressed:
|
||||
target(event.position)
|
||||
|
||||
update_cursor_mode()
|
||||
|
||||
func update_cursor_mode():
|
||||
if mouse_left_down or mouse_right_down:
|
||||
if not cursor_grabbed:
|
||||
set_process_input(true)
|
||||
total_down_mouse_delta = Vector2()
|
||||
|
||||
cursor_grabbed = true
|
||||
last_cursor_pos = get_viewport().get_mouse_position()
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
else:
|
||||
if cursor_grabbed:
|
||||
set_process_input(false)
|
||||
cursor_grabbed = false
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
get_viewport().warp_mouse(last_cursor_pos)
|
||||
|
||||
if total_down_mouse_delta.length_squared() < 8:
|
||||
target(last_cursor_pos)
|
||||
|
||||
|
||||
func rotate_delta(x_delta : float) -> void:
|
||||
y_rot += x_delta
|
||||
|
||||
while y_rot > 360:
|
||||
y_rot -= 360
|
||||
|
||||
while y_rot < 0:
|
||||
y_rot += 360
|
||||
|
||||
rotation_degrees = Vector3(0.0, y_rot, 0.0)
|
||||
|
||||
func target(position : Vector2):
|
||||
var from = camera.project_ray_origin(position)
|
||||
var to = from + camera.project_ray_normal(position) * ray_length
|
||||
|
||||
var space_state = get_world().direct_space_state
|
||||
var result = space_state.intersect_ray(from, to, [], collision_mask)
|
||||
|
||||
if result:
|
||||
if result.collider and result.collider.owner is Entity:
|
||||
var ent : Entity = result.collider.owner as Entity
|
||||
|
||||
entity.crequest_target_change(ent.get_path())
|
||||
return
|
||||
|
||||
entity.crequest_target_change(NodePath())
|
||||
else:
|
||||
entity.crequest_target_change(NodePath())
|
||||
|
||||
func cmouseover(event):
|
||||
var from = camera.project_ray_origin(event.position)
|
||||
var to = from + camera.project_ray_normal(event.position) * ray_length
|
||||
|
||||
var space_state = get_world().direct_space_state
|
||||
var result = space_state.intersect_ray(from, to, [], collision_mask)
|
||||
|
||||
if result:
|
||||
if result.collider:# and result.collider.owner is Entity:
|
||||
var mo : Entity = result.collider.owner as Entity
|
||||
|
||||
if mo == null:
|
||||
return
|
||||
|
||||
if last_mouse_over != null and last_mouse_over != mo:
|
||||
if is_instance_valid(last_mouse_over):
|
||||
last_mouse_over.onc_mouse_exit()
|
||||
|
||||
last_mouse_over = null
|
||||
|
||||
if last_mouse_over == null:
|
||||
mo.onc_mouse_enter()
|
||||
last_mouse_over = mo
|
||||
|
||||
return
|
||||
|
||||
if last_mouse_over != null:
|
||||
last_mouse_over.onc_mouse_exit()
|
||||
last_mouse_over = null
|
||||
|
||||
func analog_force_change(vector, touchpad):
|
||||
if touchpad.padname == "TouchPad":
|
||||
touchpad_dir = vector
|
||||
touchpad_dir.y *= -1
|
||||
elif touchpad.padname == "TargetPad":
|
||||
#try to target
|
||||
return
|
||||
|
||||
func queue_camera_rotation(rot : Vector2) -> void:
|
||||
queued_camera_rotaions += rot
|
||||
|
||||
remote func sset_position(position : Vector3, rotation : Vector3) -> void:
|
||||
if get_network_master() != 1:
|
||||
print(str(get_network_master()) + "psset")
|
||||
|
||||
if multiplayer.network_peer and multiplayer.is_network_server():
|
||||
entity.vrpc("cset_position", position, rotation)
|
||||
cset_position(position, rotation)
|
||||
|
||||
remote func cset_position(position : Vector3, rotation : Vector3) -> void:
|
||||
if get_network_master() != 1:
|
||||
print(str(get_network_master()) + " pcset")
|
||||
translation = position
|
||||
rotation = rotation
|
||||
|
||||
#func _setup():
|
||||
# setup_actionbars()
|
||||
|
||||
func _con_cast_started(info):
|
||||
if anim_node_state_machine != null and not casting_anim:
|
||||
anim_node_state_machine.travel("casting-loop")
|
||||
casting_anim = true
|
||||
animation_run = false
|
||||
|
||||
func _con_cast_failed(info):
|
||||
if anim_node_state_machine != null and casting_anim:
|
||||
anim_node_state_machine.travel("idle-loop")
|
||||
casting_anim = false
|
||||
|
||||
if animation_run:
|
||||
anim_node_state_machine.travel("run-loop")
|
||||
|
||||
func _con_cast_finished(info):
|
||||
if anim_node_state_machine != null:
|
||||
anim_node_state_machine.travel("cast-end")
|
||||
casting_anim = false
|
||||
|
||||
if animation_run:
|
||||
anim_node_state_machine.travel("run-loop")
|
||||
|
||||
func _con_spell_cast_success(info):
|
||||
if anim_node_state_machine != null:
|
||||
anim_node_state_machine.travel("cast-end")
|
||||
casting_anim = false
|
||||
|
||||
if animation_run:
|
||||
anim_node_state_machine.travel("run-loop")
|
||||
|
||||
|
||||
func on_c_controlled_changed(val):
|
||||
#create camera and pivot if true
|
||||
_on = val
|
||||
|
||||
set_physics_process(val)
|
||||
|
@ -33,6 +33,8 @@ transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.960532, 0 )
|
||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.875205, 0 )
|
||||
|
||||
[node name="character" parent="Body/Rotation_Helper/Model" instance=ExtResource( 2 )]
|
||||
refresh_in_editor = false
|
||||
use_lod = true
|
||||
|
||||
[node name="NamePlate" parent="." instance=ExtResource( 3 )]
|
||||
max_distance = 50.0
|
||||
|
@ -24,399 +24,7 @@ class_name PlayerGD
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
export(float) var MOUSE_SENSITIVITY : float = 0.05
|
||||
export(String) var world_path : String = ".."
|
||||
export(NodePath) var model_path : NodePath = "Rotation_Helper/Model"
|
||||
|
||||
const ray_length = 1000
|
||||
const ACCEL : float = 100.0
|
||||
const DEACCEL : float = 100.0
|
||||
const GRAVITY : float = -24.8
|
||||
const JUMP_SPEED : float = 3.8
|
||||
const MAX_SLOPE_ANGLE : float = 40.0
|
||||
const MOUSE_TARGET_MAX_OFFSET : int = 10
|
||||
|
||||
var _on : bool = true
|
||||
|
||||
var y_rot : float = 0.0
|
||||
|
||||
var vel : Vector3 = Vector3()
|
||||
var dir : Vector3 = Vector3()
|
||||
|
||||
var input_dir : Vector2 = Vector2()
|
||||
var mouse_dir : Vector2 = Vector2()
|
||||
var mouse_move_dir : Vector2 = Vector2()
|
||||
var mouse_left_down : bool = false
|
||||
var mouse_right_down : bool = false
|
||||
var touchpad_dir : Vector2 = Vector2()
|
||||
var mouse_down_delta : Vector2 = Vector2()
|
||||
var queued_camera_rotaions : Vector2 = Vector2()
|
||||
|
||||
var key_left : bool = false
|
||||
var key_right : bool = false
|
||||
var key_up : bool = false
|
||||
var key_down : bool = false
|
||||
|
||||
var cursor_grabbed : bool = false
|
||||
var last_cursor_pos : Vector2 = Vector2()
|
||||
var mouse_down_pos : Vector2 = Vector2()
|
||||
var total_down_mouse_delta : Vector2 = Vector2()
|
||||
|
||||
var camera : Camera
|
||||
var camera_pivot : Spatial
|
||||
|
||||
var animation_tree : AnimationTree
|
||||
var anim_node_state_machine : AnimationNodeStateMachinePlayback = null
|
||||
var animation_run : bool = false
|
||||
|
||||
var moving : bool = false
|
||||
var casting_anim : bool = false
|
||||
|
||||
var last_mouse_over : Entity = null
|
||||
|
||||
var world : VoxelWorld = null
|
||||
|
||||
var model_rotation_node : Spatial
|
||||
|
||||
func _ready() -> void:
|
||||
camera = $Body/CameraPivot/Camera as Camera
|
||||
camera_pivot = $Body/CameraPivot as Spatial
|
||||
|
||||
model_rotation_node = get_node(model_path)
|
||||
|
||||
animation_tree = get_character_skeleton().get_animation_tree()
|
||||
|
||||
if animation_tree != null:
|
||||
anim_node_state_machine = animation_tree["parameters/playback"]
|
||||
|
||||
set_physics_process(false)
|
||||
|
||||
func _enter_tree():
|
||||
world = get_node(world_path) as VoxelWorld
|
||||
set_physics_process(true)
|
||||
|
||||
func _physics_process(delta : float) -> void:
|
||||
if not _on:
|
||||
return
|
||||
|
||||
if world.initial_generation:
|
||||
return
|
||||
|
||||
process_input(delta)
|
||||
process_movement(delta)
|
||||
|
||||
func process_input(delta: float) -> void:
|
||||
var key_dir : Vector2 = Vector2()
|
||||
|
||||
if key_up:
|
||||
key_dir.y -= 1
|
||||
if key_down:
|
||||
key_dir.y += 1
|
||||
if key_left:
|
||||
key_dir.x -= 1
|
||||
if key_right:
|
||||
key_dir.x += 1
|
||||
|
||||
input_dir = key_dir + mouse_dir + touchpad_dir + mouse_move_dir
|
||||
|
||||
var state : int = getc_state()
|
||||
|
||||
if state & EntityEnums.ENTITY_STATE_TYPE_FLAG_ROOT != 0 or state & EntityEnums.ENTITY_STATE_TYPE_FLAG_STUN != 0:
|
||||
input_dir = Vector2()
|
||||
return
|
||||
|
||||
var input_length : float = input_dir.length_squared()
|
||||
|
||||
if input_length > 0.1:
|
||||
if anim_node_state_machine != null and not animation_run:
|
||||
anim_node_state_machine.travel("run-loop")
|
||||
animation_run = true
|
||||
|
||||
input_dir = input_dir.normalized()
|
||||
|
||||
animation_tree["parameters/run-loop/blend_position"] = input_dir
|
||||
|
||||
if (input_dir.y < 0.1):
|
||||
model_rotation_node.transform.basis = Basis(Vector3(0, acos(input_dir.x) - PI / 2.0, 0))
|
||||
else:
|
||||
model_rotation_node.transform.basis = Basis()
|
||||
else:
|
||||
if anim_node_state_machine != null and animation_run:
|
||||
anim_node_state_machine.travel("idle-loop")
|
||||
animation_run = false
|
||||
|
||||
if queued_camera_rotaions.length_squared() > 1:
|
||||
camera_pivot.rotate_delta(queued_camera_rotaions.x * 2.0, queued_camera_rotaions.y)
|
||||
queued_camera_rotaions = Vector2()
|
||||
|
||||
if input_length > 0.1:
|
||||
rotate_delta(camera_pivot.get_y_rot())
|
||||
camera_pivot.set_y_rot(0.0)
|
||||
|
||||
func process_movement(delta : float) -> void:
|
||||
var state : int = getc_state()
|
||||
|
||||
if state & EntityEnums.ENTITY_STATE_TYPE_FLAG_ROOT != 0 or state & EntityEnums.ENTITY_STATE_TYPE_FLAG_STUN != 0:
|
||||
moving = false
|
||||
return
|
||||
|
||||
if input_dir.x > 0.1 or input_dir.y > 0.1 or input_dir.x < -0.1 or input_dir.y < -0.1:
|
||||
var forward : Vector3 = Vector3(0, 0, 1).rotated(Vector3(0, 1, 0), deg2rad(y_rot))
|
||||
var right : Vector3 = forward.cross(Vector3(0, 1, 0)) * -input_dir.x
|
||||
forward *= input_dir.y #only potentially make it zero after getting the right vector
|
||||
|
||||
dir = forward
|
||||
dir += right
|
||||
|
||||
if dir.length_squared() > 0.1:
|
||||
dir = dir.normalized()
|
||||
|
||||
moving = true
|
||||
moved()
|
||||
else:
|
||||
dir = Vector3()
|
||||
moving = false
|
||||
|
||||
vel.y += delta * GRAVITY
|
||||
|
||||
var hvel : Vector3 = vel
|
||||
hvel.y = 0
|
||||
|
||||
var target : Vector3 = dir
|
||||
target *= get_speed().ccurrent
|
||||
|
||||
var accel
|
||||
if dir.dot(hvel) > 0:
|
||||
accel = ACCEL
|
||||
else:
|
||||
accel = DEACCEL
|
||||
|
||||
hvel = hvel.linear_interpolate(target, accel * delta) as Vector3
|
||||
vel.x = hvel.x
|
||||
vel.z = hvel.z
|
||||
vel = get_body().move_and_slide(vel, Vector3(0,1,0), true, 4, deg2rad(MAX_SLOPE_ANGLE))
|
||||
|
||||
if multiplayer.has_network_peer():
|
||||
if not multiplayer.is_network_server():
|
||||
rpc_id(1, "sset_position", get_body().translation, get_body().rotation)
|
||||
else:
|
||||
sset_position(get_body().translation, get_body().rotation)
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if not cursor_grabbed:
|
||||
set_process_input(false)
|
||||
return
|
||||
|
||||
if event is InputEventMouseMotion and event.device != -1:
|
||||
var s : float = ProjectSettings.get("display/mouse_cursor/sensitivity")
|
||||
|
||||
var relx : float = event.relative.x * s
|
||||
var rely : float = event.relative.y * s
|
||||
|
||||
mouse_down_delta.x += relx
|
||||
mouse_down_delta.y += rely
|
||||
|
||||
total_down_mouse_delta.x += relx
|
||||
total_down_mouse_delta.y += rely
|
||||
|
||||
get_tree().set_input_as_handled()
|
||||
|
||||
if (mouse_right_down or mouse_left_down) and event.device != -1:
|
||||
if mouse_right_down:
|
||||
camera_pivot.rotate_delta(0.0, -event.relative.y)
|
||||
rotate_delta(-event.relative.x)
|
||||
else:
|
||||
camera_pivot.rotate_delta(-relx, -rely)
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event is InputEventKey:
|
||||
var ievkey : InputEventKey = event as InputEventKey
|
||||
|
||||
if ievkey.scancode == KEY_W:
|
||||
key_up = ievkey.pressed
|
||||
if ievkey.scancode == KEY_S:
|
||||
key_down = ievkey.pressed
|
||||
if ievkey.scancode == KEY_A:
|
||||
key_left = ievkey.pressed
|
||||
if ievkey.scancode == KEY_D:
|
||||
key_right = ievkey.pressed
|
||||
|
||||
if event is InputEventMouseMotion and not (mouse_right_down or mouse_left_down) and event.device != -1:
|
||||
cmouseover(event)
|
||||
|
||||
if event is InputEventMouseButton:
|
||||
if event.button_index == BUTTON_LEFT and event.device != -1:
|
||||
mouse_left_down = event.pressed
|
||||
|
||||
if mouse_left_down:
|
||||
mouse_down_delta = Vector2()
|
||||
mouse_down_pos = event.position
|
||||
|
||||
if event.button_index == BUTTON_RIGHT and event.device != -1:
|
||||
mouse_right_down = event.pressed
|
||||
|
||||
if mouse_right_down:
|
||||
rotate_delta(camera_pivot.get_y_rot())
|
||||
camera_pivot.set_y_rot(0.0)
|
||||
|
||||
if mouse_left_down and mouse_right_down:
|
||||
mouse_move_dir.y = -1
|
||||
else:
|
||||
mouse_move_dir.y = 0
|
||||
|
||||
if event.is_pressed() and event.device != -1:
|
||||
if event.button_index == BUTTON_WHEEL_UP:
|
||||
camera_pivot.camera_distance_set_delta(-0.2)
|
||||
if event.button_index == BUTTON_WHEEL_DOWN:
|
||||
camera_pivot.camera_distance_set_delta(0.2)
|
||||
|
||||
if not event.pressed and event.button_index == BUTTON_LEFT and event.device != -1:
|
||||
if mouse_down_delta.length() < MOUSE_TARGET_MAX_OFFSET:
|
||||
target(event.position)
|
||||
|
||||
if event is InputEventScreenTouch and event.pressed:
|
||||
target(event.position)
|
||||
|
||||
update_cursor_mode()
|
||||
|
||||
func update_cursor_mode():
|
||||
if mouse_left_down or mouse_right_down:
|
||||
if not cursor_grabbed:
|
||||
set_process_input(true)
|
||||
total_down_mouse_delta = Vector2()
|
||||
|
||||
cursor_grabbed = true
|
||||
last_cursor_pos = get_viewport().get_mouse_position()
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||
else:
|
||||
if cursor_grabbed:
|
||||
set_process_input(false)
|
||||
cursor_grabbed = false
|
||||
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
|
||||
get_viewport().warp_mouse(last_cursor_pos)
|
||||
|
||||
if total_down_mouse_delta.length_squared() < 8:
|
||||
target(last_cursor_pos)
|
||||
|
||||
|
||||
func rotate_delta(x_delta : float) -> void:
|
||||
y_rot += x_delta
|
||||
|
||||
while y_rot > 360:
|
||||
y_rot -= 360
|
||||
|
||||
while y_rot < 0:
|
||||
y_rot += 360
|
||||
|
||||
get_body().rotation_degrees = Vector3(0.0, y_rot, 0.0)
|
||||
|
||||
func target(position : Vector2):
|
||||
var from = camera.project_ray_origin(position)
|
||||
var to = from + camera.project_ray_normal(position) * ray_length
|
||||
|
||||
var space_state = get_body().get_world().direct_space_state
|
||||
var result = space_state.intersect_ray(from, to, [], get_body().collision_mask)
|
||||
|
||||
if result:
|
||||
if result.collider and result.collider.owner is Entity:
|
||||
var ent : Entity = result.collider.owner as Entity
|
||||
|
||||
crequest_target_change(ent.get_path())
|
||||
return
|
||||
|
||||
crequest_target_change(NodePath())
|
||||
else:
|
||||
crequest_target_change(NodePath())
|
||||
|
||||
func cmouseover(event):
|
||||
var from = camera.project_ray_origin(event.position)
|
||||
var to = from + camera.project_ray_normal(event.position) * ray_length
|
||||
|
||||
var space_state = get_body().get_world().direct_space_state
|
||||
var result = space_state.intersect_ray(from, to, [], get_body().collision_mask)
|
||||
|
||||
if result:
|
||||
if result.collider:# and result.collider.owner is Entity:
|
||||
var mo : Entity = result.collider.owner as Entity
|
||||
|
||||
if mo == null:
|
||||
return
|
||||
|
||||
if last_mouse_over != null and last_mouse_over != mo:
|
||||
if is_instance_valid(last_mouse_over):
|
||||
last_mouse_over.onc_mouse_exit()
|
||||
|
||||
last_mouse_over = null
|
||||
|
||||
if last_mouse_over == null:
|
||||
mo.onc_mouse_enter()
|
||||
last_mouse_over = mo
|
||||
|
||||
return
|
||||
|
||||
if last_mouse_over != null:
|
||||
last_mouse_over.onc_mouse_exit()
|
||||
last_mouse_over = null
|
||||
|
||||
func analog_force_change(vector, touchpad):
|
||||
if touchpad.padname == "TouchPad":
|
||||
touchpad_dir = vector
|
||||
touchpad_dir.y *= -1
|
||||
elif touchpad.padname == "TargetPad":
|
||||
#try to target
|
||||
return
|
||||
|
||||
func queue_camera_rotation(rot : Vector2) -> void:
|
||||
queued_camera_rotaions += rot
|
||||
|
||||
remote func sset_position(position : Vector3, rotation : Vector3) -> void:
|
||||
if get_network_master() != 1:
|
||||
print(str(get_network_master()) + "psset")
|
||||
|
||||
if multiplayer.network_peer and multiplayer.is_network_server():
|
||||
vrpc("cset_position", position, rotation)
|
||||
cset_position(position, rotation)
|
||||
|
||||
remote func cset_position(position : Vector3, rotation : Vector3) -> void:
|
||||
if get_network_master() != 1:
|
||||
print(str(get_network_master()) + " pcset")
|
||||
get_body().translation = position
|
||||
get_body().rotation = rotation
|
||||
|
||||
#func _setup():
|
||||
# setup_actionbars()
|
||||
|
||||
func _con_cast_started(info):
|
||||
if anim_node_state_machine != null and not casting_anim:
|
||||
anim_node_state_machine.travel("casting-loop")
|
||||
casting_anim = true
|
||||
animation_run = false
|
||||
|
||||
func _con_cast_failed(info):
|
||||
if anim_node_state_machine != null and casting_anim:
|
||||
anim_node_state_machine.travel("idle-loop")
|
||||
casting_anim = false
|
||||
|
||||
if animation_run:
|
||||
anim_node_state_machine.travel("run-loop")
|
||||
|
||||
func _con_cast_finished(info):
|
||||
if anim_node_state_machine != null:
|
||||
anim_node_state_machine.travel("cast-end")
|
||||
casting_anim = false
|
||||
|
||||
if animation_run:
|
||||
anim_node_state_machine.travel("run-loop")
|
||||
|
||||
func _con_spell_cast_success(info):
|
||||
if anim_node_state_machine != null:
|
||||
anim_node_state_machine.travel("cast-end")
|
||||
casting_anim = false
|
||||
|
||||
if animation_run:
|
||||
anim_node_state_machine.travel("run-loop")
|
||||
|
||||
func _from_dict(dict):
|
||||
._from_dict(dict)
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
[gd_scene load_steps=7 format=2]
|
||||
[gd_scene load_steps=8 format=2]
|
||||
|
||||
[ext_resource path="res://data/models/armature_model_orig_v2.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://player/Player.gd" type="Script" id=2]
|
||||
[ext_resource path="res://ui/player_ui/player_ui.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://player/CameraPivot.gd" type="Script" id=4]
|
||||
[ext_resource path="res://player/Body.gd" type="Script" id=5]
|
||||
|
||||
[sub_resource type="CapsuleShape" id=1]
|
||||
radius = 0.266582
|
||||
@ -18,9 +19,9 @@ extents = Vector3( 0.216228, 0.0681041, 0.183397 )
|
||||
body_path = NodePath("Body")
|
||||
character_skeleton_path = NodePath("Body/Rotation_Helper/Model/character")
|
||||
script = ExtResource( 2 )
|
||||
model_path = NodePath("Body/Rotation_Helper/Model")
|
||||
|
||||
[node name="Body" type="KinematicBody" parent="."]
|
||||
script = ExtResource( 5 )
|
||||
|
||||
[node name="Body_CollisionShape" type="CollisionShape" parent="Body"]
|
||||
transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0.73, 0 )
|
||||
@ -47,6 +48,8 @@ transform = Transform( -1, 0, -3.25841e-07, 0, 1, 0, 3.25841e-07, 0, -1, 0, 0, 0
|
||||
[node name="Model" type="Spatial" parent="Body/Rotation_Helper"]
|
||||
|
||||
[node name="character" parent="Body/Rotation_Helper/Model" instance=ExtResource( 1 )]
|
||||
refresh_in_editor = false
|
||||
use_lod = true
|
||||
|
||||
[node name="GUILayer" parent="." instance=ExtResource( 3 )]
|
||||
[connection signal="onc_open_loot_winow_request" from="." to="GUILayer" method="_on_Player_onc_open_loot_winow_request"]
|
||||
|
Loading…
Reference in New Issue
Block a user