Updated KinematicBody3D to CharacterBody3D. Cleaned up Chat code, chat works on RPC

This commit is contained in:
unfa 2021-06-07 19:11:42 +02:00
parent b1e2eec834
commit 709b696188
3 changed files with 26 additions and 47 deletions

View file

@ -1,4 +1,4 @@
extends KinematicBody3D
extends CharacterBody3D
@export var mouse_sensitivity := 0.35
#var speed := 15
@ -17,11 +17,11 @@ extends KinematicBody3D
@onready var mesh = $Mesh
@onready var body_height = body.shape.height
@onready var body_y = body.translation.y
@onready var body_y = body.position.y
@onready var mesh_height = mesh.mesh.mid_height
@onready var mesh_y = mesh.translation.y
@onready var climb_check_y = climb_check.translation.y
@onready var ground_check_y = ground_check.translation.y
@onready var mesh_y = mesh.position.y
@onready var climb_check_y = climb_check.position.y
@onready var ground_check_y = ground_check.position.y
var input_active = false
@ -40,13 +40,13 @@ var climb_state := 0.0 :
#print("climb_state is now ", factor)
climb_state = factor
body.shape.height = body_height - factor * climb_height
body.translation.y = body_y + factor * climb_height / 2
body.position.y = body_y + factor * climb_height / 2
mesh.mesh.mid_height = mesh_height - factor * climb_height
mesh.translation.y = mesh_y + factor * climb_height / 2
mesh.position.y = mesh_y + factor * climb_height / 2
ground_check.translation.y = ground_check_y + factor * climb_height / 2
climb_check.translation.y = climb_check_y + factor * climb_height / 2
ground_check.position.y = ground_check_y + factor * climb_height / 2
climb_check.position.y = climb_check_y + factor * climb_height / 2
var direction := Vector3.ZERO
var accel := 0
@ -66,10 +66,7 @@ var gravity := 28
var jump := 14
var velocity := Vector3.ZERO
var movement := Vector3.ZERO
var gravity_vec := Vector3.ZERO
var slide := Vector3.ZERO
var snap := Vector3.ZERO
func _ready() -> void:
#Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
@ -135,14 +132,14 @@ func _physics_process(delta):
velocity = velocity.lerp(direction * speed, accel * delta)
movement = velocity + gravity_vec
slide = move_and_slide_with_snap(movement, snap, Vector3.UP)
linear_velocity = velocity + gravity_vec
#slide = move_and_slide_with_snap(movement, snap, Vector3.UP)
move_and_slide()
if not is_on_floor() and not ground_check.is_colliding(): # while in mid-air collisions affect momentum
velocity.x = slide.x
velocity.z = slide.z
gravity_vec.y = slide.y
velocity.x = linear_velocity.x
velocity.z = linear_velocity.z
gravity_vec.y = linear_velocity.y
# (stair) climbing

View file

@ -15,27 +15,27 @@ height = 0.9
radius = 0.25
height = 0.5
[node name="Player" type="KinematicBody3D"]
[node name="Player" type="CharacterBody3D"]
script = ExtResource( 1 )
[node name="Mesh" type="MeshInstance3D" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.852763, 0 )
transform = Transform3D( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.852763, 0 )
mesh = SubResource( 1 )
surface_material_override/0 = null
script = null
[node name="Head" type="Node3D" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.45276, 0 )
transform = Transform3D( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.45276, 0 )
script = null
[node name="Camera" type="Camera3D" parent="Head"]
transform = Transform( 1, 0, 2.38419e-07, 0, 1, 0, -2.38419e-07, 0, 1, 0, 0, 0 )
transform = Transform3D( 1, 0, 2.38419e-07, 0, 1, 0, -2.38419e-07, 0, 1, 0, 0, 0 )
current = true
fov = 90.0
script = null
[node name="Hand" type="Node3D" parent="Head/Camera"]
transform = Transform( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.3, -0.4, -0.6 )
transform = Transform3D( -4.37114e-08, 0, -1, 0, 1, 0, 1, 0, -4.37114e-08, 0.3, -0.4, -0.6 )
script = null
[node name="Weapon" parent="Head/Camera/Hand" instance=ExtResource( 3 )]
@ -44,24 +44,24 @@ script = null
script = null
[node name="Body" type="CollisionShape3D" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.852763, 0 )
transform = Transform3D( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.852763, 0 )
shape = SubResource( 2 )
script = null
[node name="Feet" type="CollisionShape3D" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.252763, 0 )
transform = Transform3D( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.252763, 0 )
shape = SubResource( 3 )
disabled = true
script = null
[node name="GroundCheck" type="RayCast3D" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.952763, 0 )
transform = Transform3D( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.952763, 0 )
target_position = Vector3( 0, -1.1, 0 )
debug_shape_thickness = 5.0
script = null
[node name="ClimbCheck" type="RayCast3D" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.60905, -0.5 )
transform = Transform3D( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.60905, -0.5 )
target_position = Vector3( 0, -1.35, 0 )
script = null
@ -69,5 +69,5 @@ script = null
script = null
[node name="Camera3D" type="Camera3D" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 3 )
transform = Transform3D( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 3 )
script = null

View file

@ -7,24 +7,7 @@ extends Control
@onready var chat_editor = $VBoxContainer/Typing/Editor
@onready var chat_label = $VBoxContainer/Typing/Label
#class chat_message:
# var sender_id := 0
# var team := 0
# var message := ''
#
# func _init(sender_id, team, message):
# self.sender_id = sender_id
# self.team = team
# self.message = message
#@remotesync var message: chat_message:
# set(new_message):
# print("message changed : ", new_message)
# $VBoxContainer/ChatHistory.text += "\n" + str(new_message[0]) + ' : ' + new_message[2]
enum ChatState {INACTIVE, TYPING_ALL, TYPING_TEAM}
enum GameFocus {MENU, GAME, CHAT, AWAY} # copied from Main.gd TODO: delete this
var state = ChatState.INACTIVE :
@ -77,8 +60,7 @@ func _on_LineEdit_text_entered(new_text):
# RPC is currently not implemented in the engine
var sender_id = get_tree().get_network_unique_id()
var new_message = [sender_id, 0, new_text]
chat_message(sender_id, 0, new_text)
#chat_message.rpc(get_tree().get_network_unique_id(), $VBoxContainer/Typing/LineEdit.text)
rpc(&'chat_message',sender_id, 0, new_text)
chat_editor.text = ''
state = 0 #ChatState.INACTIVE
main.focus = 0 #main.GameFocus.GAME