diff --git a/client/scenes/entities/bloc/bloc.tscn b/client/scenes/entities/bloc/bloc.tscn index 6d021e8d13c903885f228214692a6ae0c54fd89b..8d6ebc3ba58db8abda997e096e88ea203ec61150 100644 --- a/client/scenes/entities/bloc/bloc.tscn +++ b/client/scenes/entities/bloc/bloc.tscn @@ -1,17 +1,10 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=2 format=2] [sub_resource type="CubeMesh" id=1] -[sub_resource type="BoxShape" id=2] - [node name="Bloc" type="Spatial"] [node name="MeshInstance" type="MeshInstance" parent="."] transform = Transform( 0.5, 0, 0, 0, 0.3, 0, 0, 0, 1, 0, 0, 0 ) mesh = SubResource( 1 ) material/0 = null - -[node name="StaticBody" type="StaticBody" parent="MeshInstance"] - -[node name="CollisionShape" type="CollisionShape" parent="MeshInstance/StaticBody"] -shape = SubResource( 2 ) diff --git a/client/scenes/entities/player/player.gd b/client/scenes/entities/player/player.gd index 7916621ee050bdf09226cc3c008d89c8e5667c54..b1de2aa2cdf1c54b31805c473a44b2da1b719249 100644 --- a/client/scenes/entities/player/player.gd +++ b/client/scenes/entities/player/player.gd @@ -1,4 +1,5 @@ extends KinematicBody -remote func getRemoteMovement(position): - self.move_and_slide(position, Vector3(0,1,0), 0.05, 4) \ No newline at end of file +# Update the player's position based on the position computed by the remote scene on the server +puppet func getRemoteMovement(position): + self.set_translation(position) \ No newline at end of file diff --git a/client/scenes/entities/player/player.tscn b/client/scenes/entities/player/player.tscn index d768d61dc6f862e4fd299022eef47f2211dd2ba5..3cfc97070d9f06f2c9f605a0f46537fc35f9860a 100644 --- a/client/scenes/entities/player/player.tscn +++ b/client/scenes/entities/player/player.tscn @@ -1,17 +1,10 @@ -[gd_scene load_steps=3 format=2] +[gd_scene load_steps=2 format=2] [ext_resource path="res://scenes/entities/player/player.gd" type="Script" id=1] -[sub_resource type="BoxShape" id=1] -extents = Vector3( 0.175, 0.275, 0.7 ) - [node name="Player" type="KinematicBody"] script = ExtResource( 1 ) -[node name="Body_CollisionShape" type="CollisionShape" parent="."] -transform = Transform( 1, 0, 0, 0, 0, -1, 0, 1, 0, 0, 0.65, 0 ) -shape = SubResource( 1 ) - [node name="Model" type="Spatial" parent="."] [node name="CSGBox" type="CSGBox" parent="Model"] diff --git a/client/scenes/levels/lobby/lobby.gd b/client/scenes/levels/lobby/lobby.gd index 41dbeca82c2e7f905ca5d63dd8c12bc89bccd3b5..0603a645ee166e46207be127816417a0dc1141c0 100644 --- a/client/scenes/levels/lobby/lobby.gd +++ b/client/scenes/levels/lobby/lobby.gd @@ -29,7 +29,6 @@ func _on_joinButton_pressed(): #func _player_connected(): # print("You successfuly joined the server with the id " + str(gamestate.get_network_unique_id())) # -# #func _connection_failed(): # print("Connection failure") # diff --git a/client/scenes/levels/testnetwork/Node.gd b/client/scenes/levels/testnetwork/Node.gd deleted file mode 100644 index a936c80ab4bae3cc2a2608e4e4411a1476f74423..0000000000000000000000000000000000000000 --- a/client/scenes/levels/testnetwork/Node.gd +++ /dev/null @@ -1,40 +0,0 @@ -#client - -extends Node - -var peer = NetworkedMultiplayerENet.new() -export var is_server = false - -func _ready(): - peer.create_client("91.121.81.74",10001) - get_tree().set_network_peer(peer) - - get_tree().connect("connected_to_server", self, "_connected_ok") #connexion effectuée - get_tree().connect("connection_failed", self, "_connected_failed") #connextion error - get_tree().connect("server_disconnected", self, "_server_disconnected") #déconnexion - - - - - -remote func get_message(mess): - if mess == "quit": - print("Received order to quit") - get_tree().set_network_peer(null) - get_tree().quit() - else: - print(mess) - -#Quand connexion effectuée -func _connected_ok(): - print("Connection to server successful") - set_network_master(get_tree().get_network_unique_id()) - rpc("get_message","Hello there") - rpc("get_message","quit") - -#Quand connection error -func _connected_failed(): - print("Failed to connect to server") - - - diff --git a/client/scenes/levels/testnetwork/Node.tscn b/client/scenes/levels/testnetwork/Node.tscn deleted file mode 100644 index d8855e2060e5c05f623c67f3139022c5c31e9bd3..0000000000000000000000000000000000000000 --- a/client/scenes/levels/testnetwork/Node.tscn +++ /dev/null @@ -1,6 +0,0 @@ -[gd_scene load_steps=2 format=2] - -[ext_resource path="res://scenes/levels/testnetwork/Node.gd" type="Script" id=1] - -[node name="Node" type="Node"] -script = ExtResource( 1 ) diff --git a/cmi2/Client/project.godot b/cmi2/Client/project.godot deleted file mode 100644 index d403908ded27630d4bc743b1c362e3c9e646e1a3..0000000000000000000000000000000000000000 --- a/cmi2/Client/project.godot +++ /dev/null @@ -1,24 +0,0 @@ -; Engine configuration file. -; It's best edited using the editor UI and not directly, -; since the parameters that go here are not all obvious. -; -; Format: -; [section] ; section goes between [] -; param=value ; assign values to parameters - -config_version=4 - -_global_script_classes=[ ] -_global_script_class_icons={ - -} - -[application] - -config/name="Client" -run/main_scene="res://Scenes/Level.tscn" -config/icon="res://img/icon.png" - -[rendering] - -environment/default_environment="res://default_env.tres" diff --git a/cmi2/Server/project.godot b/cmi2/Server/project.godot deleted file mode 100644 index ccfeb9197430cfd5bf794e22057e6f58625ab851..0000000000000000000000000000000000000000 --- a/cmi2/Server/project.godot +++ /dev/null @@ -1,24 +0,0 @@ -; Engine configuration file. -; It's best edited using the editor UI and not directly, -; since the parameters that go here are not all obvious. -; -; Format: -; [section] ; section goes between [] -; param=value ; assign values to parameters - -config_version=4 - -_global_script_classes=[ ] -_global_script_class_icons={ - -} - -[application] - -config/name="Server" -run/main_scene="res://Scenes/Server.tscn" -config/icon="res://img/icon.png" - -[rendering] - -environment/default_environment="res://default_env.tres" diff --git a/server/scenes/autoloads/gamestate.gd b/server/scenes/autoloads/gamestate.gd index 6f1606fa2d1d85e2b53b08fc17ec2a5a5105147b..d355e540a5609abbc53da1733feff5572b5593a6 100644 --- a/server/scenes/autoloads/gamestate.gd +++ b/server/scenes/autoloads/gamestate.gd @@ -3,7 +3,7 @@ extends Node const GAMEPATH = "/root/game/" const PORT = 10001 -const MAX_CLIENTS = 2 +const MAX_CLIENTS = 1 var players = {} diff --git a/server/scenes/entities/player/player.gd b/server/scenes/entities/player/player.gd index e8ed31cbb58b03fdbe56f486655607ed7b7e5d2b..3e334ba2a59d1a463002d15cca31838f9c1e6b1b 100644 --- a/server/scenes/entities/player/player.gd +++ b/server/scenes/entities/player/player.gd @@ -21,22 +21,19 @@ const GRAVITY:float = -28.0 # Velocity updated continuously by move_and_slide var vel:Vector3 = Vector3() -var motion:Vector3 = Vector3() + +const FLOOR_NORMAL:Vector3 = Vector3(0,1,0) + +var motion:float = 0 # called by the engine func _physics_process(delta): processMovement(delta) - # TODO: Reactivate if we don't use it from processMovement - #broadcastMovement(delta) + broadcastMovement(delta) # Called from the game script to update the vars func getPlayerInputs(movementInput, sprintInput, jumpInput): - motion = Vector3() - - motion.x = movementInput - motion.y= 0 - motion.z = 0 - + motion = movementInput isSprinting = sprintInput isJumping = jumpInput @@ -49,7 +46,8 @@ func processMovement(delta): vel.y += delta * GRAVITY # Speed of the player - var target = motion + var target = Vector3(motion, 0, 0) + if isSprinting: target *= MAX_SPRINT_SPEED else: @@ -57,10 +55,8 @@ func processMovement(delta): # Acceleration of the player if he is moving horizontally var accel - var hvel:Vector3 = vel - hvel.y = 0 - hvel.z = 0 - if motion.dot(hvel)>0: + var hvel:Vector3 = Vector3(vel.x,0,0) + if target.dot(hvel)>0: if isSprinting: accel = SPRINT_ACCEL else: @@ -68,19 +64,12 @@ func processMovement(delta): else: accel = DEACCEL - # Interpolating speed and acceleration through time - hvel = hvel.linear_interpolate(target, accel * delta) - - # Final velocity - vel.x = hvel.x - - # Send the velocity before its alteration by move_and_slide. - # (The alteration will be sent after modification by the inputs of the last iteration.) - # It is not filthy. - broadcastMovement(delta) + # Interpolating speed and acceleration through time and getting it + vel.x = hvel.linear_interpolate(target, accel * delta).x # Update the velocity after the collisions (physical engine ftw) - vel = self.move_and_slide(vel, Vector3(0,1,0), 0.05, 4) + vel = self.move_and_slide(vel, FLOOR_NORMAL) func broadcastMovement(delta): - rpc("getRemoteMovement", vel) \ No newline at end of file + # Send the position of the player + rpc("getRemoteMovement", self.get_translation()) \ No newline at end of file