From 5dbf4b3f0a9297e00cd67e968df237ceb7f3d2d9 Mon Sep 17 00:00:00 2001 From: osquallo Date: Fri, 27 Mar 2020 12:43:49 +0100 Subject: [PATCH] EDIT changement de la methode de deplacement du personnage et diverse bricoles --- .../terrains/demo/water/water_fx.shader | 43 ++++++++++++ assets/interfaces/reticle.png | Bin 0 -> 10205 bytes project.godot | 45 ++++++++++++- ressources/scripts/entity.gd | 15 +++-- scenes/creatures/ra/ra.tscn | 8 ++- scenes/creatures/ra/ra_model.gd | 43 ++++++++++++ scenes/game/game.gd | 32 +++++---- scenes/game/game.tscn | 5 +- scenes/player/camera/camera_rig.tscn | 44 ++++++++++++ scenes/player/player.gd | 63 +++++++++++++++++- scenes/player/player.tscn | 7 ++ 11 files changed, 278 insertions(+), 27 deletions(-) create mode 100644 assets/decors/terrains/demo/water/water_fx.shader create mode 100644 assets/interfaces/reticle.png create mode 100644 scenes/creatures/ra/ra_model.gd create mode 100644 scenes/player/camera/camera_rig.tscn diff --git a/assets/decors/terrains/demo/water/water_fx.shader b/assets/decors/terrains/demo/water/water_fx.shader new file mode 100644 index 0000000..64020d5 --- /dev/null +++ b/assets/decors/terrains/demo/water/water_fx.shader @@ -0,0 +1,43 @@ +shader_type spatial; +render_mode unshaded, cull_disabled, blend_mix; + +uniform float mist_level = 0.0; +uniform vec4 mist_color : hint_color = vec4( 1.0, 0.0, 1.0, 1.0 ); +uniform float mist_height = 0.0; +uniform float mist_distance = 25.0; + +varying mat4 CAMERA; + +void vertex() +{ + POSITION = vec4(VERTEX, 1.0); + CAMERA = CAMERA_MATRIX; +} + +void fragment() +{ + float depth = texture(DEPTH_TEXTURE, SCREEN_UV).x; + vec3 ndc = vec3(SCREEN_UV, depth) * 2.0 - 1.0; + + vec4 view = INV_PROJECTION_MATRIX * vec4(ndc, 1.0); + view.xyz /= view.w; + float linear_depth = -view.z; + + vec4 world = CAMERA * INV_PROJECTION_MATRIX * vec4(ndc, 1.0); + vec3 world_position = world.xyz / world.w; + + if ( linear_depth*mist_level <= mist_distance ) + { + ALBEDO = mist_color.rgb * mist_level; + ALPHA = (linear_depth*mist_level)/mist_distance; + } + else + { + ALBEDO = mist_color.rgb; + ALPHA = 1.0; + } +// if ( world_position.y > 0.2 && world_position.y >= mist_height ) +// { +// ALPHA *= mist_height/world_position.y; +// } +} \ No newline at end of file diff --git a/assets/interfaces/reticle.png b/assets/interfaces/reticle.png new file mode 100644 index 0000000000000000000000000000000000000000..8b8b0e0a7b40d088632df49800efac0154c50256 GIT binary patch literal 10205 zcmdUVc{r5c|M!_0hODU%Arg_TkRfC(>m-sag^(DGwI(5Crp=^8mNa9{R@RZSZ}Tao zG?Q&)XHrIXvhUBW@9%qE&!5kqzh^FUjk(X9<$mAiocC)vkE|?BdAUTn006vbGb3vN z;LyKtz=?!D7DE{8&<7jt4BCbhdWCbk6QS>W0?jVt0N`udeZ!Iz`3^!CMQ$2jx_L1G zb2Iqr4G$0;9IWK+?}NK`HPAyT;D%?)jE*P(hXLB?v`t9r^x!z^RGNj2+)8za~(Q?epDg#v#yRrr2< z&Oxs*viL{FJWDP*N7Fntz2VXZ+5VqbVc+#UXWy=@AjIa**7;2A~tZ&_<~R#uRSC0=c_|)w+;!fLdlOk@4*+b2TfLA7P3&q-U7o`3d*9 zDMZch-|VHmpYs6gR(A~W!I#q~M~o#XFH@)NFIuif%t;2~_i-*G!pPl2#uBr!#Hpe) z=nPj7cPgHwNLZr#3}$uTZt2>H6U%11JNVdH8^40r6}Z01<0oT5fEkd>Xmz0K$qlzg z(JHR0__zGcu^&&k9+=}RjoHUlVcJBnER08f1Bc7yP_3_0e^I=h?Ged09T=PI_hRr+4HM=Lt<1_=d#Wp@Or`nL}M`H11WfI zdD*R($1AeGh#{Tf=^V~DcY|wJK^xP9)kPhoiihMk5Y!s z_RJlJvWi3wEy z+287_KgTm?V>C5UBb@&bW`N7@Rb4S*!k9u2SKg+Ehieah?4O*;)%s!D)c#F@O%=y3 zv$yD_j$Y^=p-lTlEi=Kj__W8{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m6L2VK3jh%ilMB)kdz!g_<{^gFH@ce#WoL*;oCId?#!6=EsT`n;e6@$0wWv z=NcpRg5eZc00=N@+I~7Il0?LPX zlm3NoN>|AgqT<4`T#v~f_HT1~9FX7`DC6;G$QE+`J*%VLiysUsK)gV^R>|a)IK)`b zV4RyC9WE{VdE@By)EoUwUFIOGby{Hl^efw-U9qI7s&X|*WT96>oGm>|r+N0cE`J zd|&A_?+jQqc#1-21X$J!;VZA?PiN9~dpD%yD+QK8SW0&~3-W>|fBZ|-9Ju^o6H|3Z z&_kyFv0UwFajwqo;Oh(X#ykrf3;X6ei6QlqZaHY4>16984BGyx*s`2SWAS8^kExtt zD+d8VHKk8-23D=Ds*E>ULBM1#E6ZZA0 zu++Xc$v1L$q&#+zltpzc5{ygJuRS;@KgsQMK2+LrVNBDb>*E8(Ex)18WJ?ub<_QVD zH{2fgrpR&kzi!maoa$IrD3y`Yo2WXJ59PX!eQII*oJ{wycb|}`?cnXzV_LX!dwk#i z?*Sc~m%Vw*NajVVdLrGo&O=4KS#ENsk++WBH-@M?_*|N1ntpSf|T>7ZdGC13nzzv{A%*Q&mo`iM=0P*-GQEi0vpOr^W33gU95w*70Dpj%BY>$iGqaNQoam`*|WiXC*Y)&;GB>;NF+E^_52WZa>f$ S?1YZu0kpBDQOOzCyZ;9Qg5<;i literal 0 HcmV?d00001 diff --git a/project.godot b/project.godot index 7c27f90..f464b1f 100644 --- a/project.godot +++ b/project.godot @@ -8,9 +8,50 @@ config_version=4 -_global_script_classes=[ ] +_global_script_classes=[ { +"base": "Spatial", +"class": "CameraRig", +"language": "GDScript", +"path": "res://ressources/scripts/player/camera/camera_rig.gd" +}, { +"base": "State", +"class": "CameraState", +"language": "GDScript", +"path": "res://ressources/scripts/player/camera/camera_state.gd" +}, { +"base": "Spatial", +"class": "Mannequiny", +"language": "GDScript", +"path": "res://scenes/creatures/ra/ra_model.gd" +}, { +"base": "KinematicBody", +"class": "Player", +"language": "GDScript", +"path": "res://ressources/scripts/player/player.gd" +}, { +"base": "State", +"class": "PlayerState", +"language": "GDScript", +"path": "res://ressources/scripts/player/player_state.gd" +}, { +"base": "Node", +"class": "State", +"language": "GDScript", +"path": "res://ressources/scripts/state_machine/state.gd" +}, { +"base": "Node", +"class": "StateMachine", +"language": "GDScript", +"path": "res://ressources/scripts/state_machine/state_machine.gd" +} ] _global_script_class_icons={ - +"CameraRig": "", +"CameraState": "", +"Mannequiny": "", +"Player": "", +"PlayerState": "", +"State": "", +"StateMachine": "" } [application] diff --git a/ressources/scripts/entity.gd b/ressources/scripts/entity.gd index d5a1af6..9cf582d 100644 --- a/ressources/scripts/entity.gd +++ b/ressources/scripts/entity.gd @@ -6,11 +6,13 @@ export(bool) var gravity_enabled = true var creature = null -func _process( delta ): - if self.gravity_enabled and $model: - for child in $model.get_children(): - if child is KinematicBody: - child.move_and_slide( Vector3( 0.0, -9.81, 0.0 ), Vector3( 0.0, 1.0, 0.0 ), true ) +var is_moving = false + +#func _process( delta ): +# if self.gravity_enabled and $model: +# for child in $model.get_children(): +# if child is KinematicBody: +# child.move_and_slide( Vector3( 0.0, -9.81, 0.0 ), Vector3( 0.0, 1.0, 0.0 ), true ) func move( m_movment ): @@ -21,7 +23,8 @@ func move( m_movment ): spatial.rotate( Vector3( 0.0, 1.0, 0.0 ), child.rotation.y ) spatial.translate( m_movment ) child.move_and_slide( spatial.translation*10.0, Vector3( 0.0, 1.0, 0.0 ), true ) - spatial.queue_free() + spatial.queue_free() + func turn( m_rotation ): if $model: diff --git a/scenes/creatures/ra/ra.tscn b/scenes/creatures/ra/ra.tscn index b46c662..ba42209 100644 --- a/scenes/creatures/ra/ra.tscn +++ b/scenes/creatures/ra/ra.tscn @@ -11,16 +11,20 @@ height = 0.827082 [node name="ra" type="KinematicBody"] [node name="spring_arm" type="Spatial" parent="."] -transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.73134, -1.7404 ) +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 2 ) [node name="camera" type="Camera" parent="spring_arm"] -transform = Transform( -0.999408, 0.0139118, -0.0314544, 0.00553681, 0.967693, 0.252072, 0.033945, 0.251749, -0.967197, 0, -1.19209e-07, 1.19209e-07 ) +transform = Transform( 0.999983, -0.00572465, 0, 0.00553979, 0.967694, 0.252069, -0.00144301, -0.252065, 0.967709, 0, -1.19209e-07, 1.19209e-07 ) [node name="model_static" parent="." instance=ExtResource( 1 )] visible = false [node name="model" parent="." instance=ExtResource( 2 )] +transform = Transform( -1, 0, -3.25841e-07, 0, 1, 0, 3.25841e-07, 0, -1, 0, 0, 0 ) [node name="collision" type="CollisionShape" parent="."] transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0.808348, 0 ) shape = SubResource( 1 ) + +[node name="camera_target" type="Position3D" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.5, 2 ) diff --git a/scenes/creatures/ra/ra_model.gd b/scenes/creatures/ra/ra_model.gd new file mode 100644 index 0000000..3328b43 --- /dev/null +++ b/scenes/creatures/ra/ra_model.gd @@ -0,0 +1,43 @@ +extends Spatial +class_name Mannequiny +# Controls the animation tree's transitions for this animated character. + +# # It has a signal connected to the player state machine, and uses the resulting +# state names to translate them into the states for the animation tree. + + +enum States {IDLE, RUN, AIR, LAND} + +onready var animation_tree: AnimationTree = $animation_tree +onready var _playback: AnimationNodeStateMachinePlayback = animation_tree["parameters/playback"] + +var move_direction: = Vector3.ZERO setget set_move_direction +var is_moving: = false setget set_is_moving + + +func _ready() -> void: + animation_tree.active = true + + +func set_move_direction(direction: Vector3) -> void: + move_direction = direction + animation_tree["parameters/walk/blend_position"] = direction.length() + + +func set_is_moving(value: bool) -> void: + is_moving = value +# animation_tree["parameters/conditions/is_moving"] = value + + +func transition_to(state_id: int) -> void: + match state_id: + States.IDLE: + _playback.travel("idle") + States.LAND: + _playback.travel("land") + States.RUN: + _playback.travel("walk") + States.AIR: + _playback.travel("jump") + _: + _playback.travel("idle") diff --git a/scenes/game/game.gd b/scenes/game/game.gd index ff471e4..9b8ce4f 100644 --- a/scenes/game/game.gd +++ b/scenes/game/game.gd @@ -16,22 +16,25 @@ var heightmap = null func _input( event ): var movment = Vector3( 0.0, 0.0, 0.0 ) var rotation = Vector3( 0.0, 0.0, 0.0 ) - if event.is_action( "move_forward" ): - movment.z += self.player_speed - elif event.is_action( "move_backward" ): - movment.z -= self.player_speed - elif event.is_action( "move_left" ): + $creatures/player.is_moving = false + if event.is_action( "move_forward" ) and event.is_pressed(): + movment.z += self.player_speed * Input.get_action_strength("move_forward") + $creatures/player.is_moving = true + elif event.is_action( "move_backward" ) and event.is_pressed(): + movment.z -= self.player_speed * Input.get_action_strength("move_backward") + $creatures/player.is_moving = true + elif event.is_action( "move_left" ) and event.is_pressed(): movment.x += self.player_speed - elif event.is_action( "move_right" ): + elif event.is_action( "move_right" ) and event.is_pressed(): movment.x -= self.player_speed - if event.is_action( "turn_left" ): + if event.is_action( "turn_left" ) and event.is_pressed(): rotation.y += self.player_rotation_speed - elif event.is_action( "turn_right" ): + elif event.is_action( "turn_right" ) and event.is_pressed(): rotation.y -= self.player_rotation_speed - $creatures/player.turn( rotation ) - $creatures/player.move( movment ) +# $creatures/player.turn( rotation ) +# $creatures/player.move( movment ) if event.is_action( "zoom_in" ): self.camera_zoom -= self.camera_zoom_speed @@ -56,12 +59,15 @@ func _process( delta ): # $camera_base.translate( camera_translation ) # camera_translation = Vector3() # $camera_base.rotate( Vector3( 0.0, 1.0, 0.0 ), deg2rad( camera_rotation ) ) + + $creatures/player.rotate_camera_arm( Vector3( 0.0, 1.0, 0.0 ), deg2rad( self.mouse_delta.x ) ) - + $creatures/player.move_camera( Vector3( 0.0, 0.0, camera_zoom ) ) - $creatures/player.rotate_camera( Vector3( 1.0, 0.0, 0.0 ), deg2rad(-self.mouse_delta.y ) ) - + $creatures/player.rotate_camera( Vector3( 1.0, 0.0, 0.0 ), deg2rad( self.mouse_delta.y ) ) + + # camera_rotation = 0.0 self.camera_zoom = 0.0 self.mouse_delta = Vector2( 0.0, 0.0 ) diff --git a/scenes/game/game.tscn b/scenes/game/game.tscn index c791cb9..8ee779f 100644 --- a/scenes/game/game.tscn +++ b/scenes/game/game.tscn @@ -23,8 +23,8 @@ noise = SubResource( 1 ) [sub_resource type="ShaderMaterial" id=3] resource_local_to_scene = true shader = ExtResource( 5 ) -shader_param/iTime = 6560.62 -shader_param/iFrame = 391307 +shader_param/iTime = 1.16881 +shader_param/iFrame = 78 shader_param/COVERAGE = 0.5 shader_param/THICKNESS = 25.0 shader_param/ABSORPTION = 1.031 @@ -107,6 +107,7 @@ transform = Transform( 10, 0, 0, 0, 10, 0, 0, 0, 10, 0, 0, 0 ) [node name="creatures" type="Spatial" parent="."] [node name="player" parent="creatures" instance=ExtResource( 1 )] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 3.07161, 14.4696 ) [node name="mist_fx" type="MeshInstance" parent="."] cast_shadow = 0 diff --git a/scenes/player/camera/camera_rig.tscn b/scenes/player/camera/camera_rig.tscn new file mode 100644 index 0000000..806d583 --- /dev/null +++ b/scenes/player/camera/camera_rig.tscn @@ -0,0 +1,44 @@ +[gd_scene load_steps=9 format=2] + +[ext_resource path="res://ressources/scripts/player/camera/aim_target.gd" type="Script" id=1] +[ext_resource path="res://ressources/scripts/player/camera/spring_arm.gd" type="Script" id=2] +[ext_resource path="res://ressources/scripts/player/camera/camera_rig.gd" type="Script" id=3] +[ext_resource path="res://ressources/scripts/state_machine/state_machine.gd" type="Script" id=4] +[ext_resource path="res://ressources/scripts/player/camera/states/camera.gd" type="Script" id=5] +[ext_resource path="res://ressources/scripts/player/camera/states/default.gd" type="Script" id=6] +[ext_resource path="res://ressources/scripts/player/camera/states/aim.gd" type="Script" id=7] +[ext_resource path="res://assets/interfaces/reticle.png" type="Texture" id=8] + +[node name="camera_rig" type="Spatial"] +script = ExtResource( 3 ) + +[node name="interpolated_camera" type="InterpolatedCamera" parent="."] +target = NodePath("../../spring_arm/camera_target") +speed = 7.0 + +[node name="aim_ray" type="RayCast" parent="interpolated_camera"] + +[node name="spring_arm" type="SpringArm" parent="."] +spring_length = 4.5 +script = ExtResource( 2 ) + +[node name="camera_target" type="Position3D" parent="spring_arm"] + +[node name="aim_target" type="Sprite3D" parent="."] +texture = ExtResource( 8 ) +script = ExtResource( 1 ) + +[node name="state_machine" type="Node" parent="."] +script = ExtResource( 4 ) +initial_state = NodePath("camera/default") + +[node name="camera" type="Node" parent="state_machine"] +script = ExtResource( 5 ) + +[node name="default" type="Node" parent="state_machine/camera"] +script = ExtResource( 6 ) + +[node name="aim" type="Node" parent="state_machine/camera"] +script = ExtResource( 7 ) + +[node name="tween" type="Tween" parent="state_machine/camera/aim"] diff --git a/scenes/player/player.gd b/scenes/player/player.gd index c6f3935..80a6551 100644 --- a/scenes/player/player.gd +++ b/scenes/player/player.gd @@ -1,12 +1,71 @@ extends "res://ressources/scripts/entity.gd" +onready var player = $model/ra +onready var camera = $model/ra/spring_arm +onready var skin = $model/ra/model +export var max_speed: = 6.0 +export var move_speed: = 5.0 +export var gravity = -100.0 +export var jump_impulse = 25 +export(float, 0.1, 20.0, 0.1) var rotation_speed_factor: = 0.01 + +var velocity: = Vector3.ZERO func _ready(): +# $camera.make_current() $model/ra/spring_arm/camera.make_current() +func _process( delta ): + + var input_direction: = self.get_input_direction() + + # Calculate a move direction vector relative to the camera + # The basis stores the (right, up, -forwards) vectors of our camera. + var forwards: Vector3 = self.camera.global_transform.basis.z * input_direction.z + var right: Vector3 = self.camera.global_transform.basis.x * input_direction.x + var move_direction: = forwards + right + if move_direction.length() > 1.0: + move_direction = move_direction.normalized() + move_direction.y = 0 +# skin.move_direction = move_direction + + # Rotation +# if move_direction: +# var target_direction = player.transform.looking_at(player.global_transform.origin + move_direction, Vector3.UP) +# player.transform = player.transform.interpolate_with(target_direction, rotation_speed_factor * delta) + + player.rotate_y( rotation_speed_factor * (Input.get_action_strength("turn_left") - Input.get_action_strength("turn_right")) ) + + # Movement + velocity = self.calculate_velocity(velocity, move_direction, delta) + velocity = player.move_and_slide(velocity, Vector3.UP, true) + + if move_direction: + $model/ra/model/AnimationPlayer.play( "walk" ) + else: + $model/ra/model/AnimationPlayer.play( "idle" ) + +static func get_input_direction() -> Vector3: + return Vector3( + Input.get_action_strength("move_right") - Input.get_action_strength("move_left"), + 0, + Input.get_action_strength("move_backward") - Input.get_action_strength("move_forward") + ) +func calculate_velocity( + velocity_current: Vector3, + move_direction: Vector3, + delta: float + ) -> Vector3: + var velocity_new := move_direction * move_speed + if velocity_new.length() > max_speed: + velocity_new = velocity_new.normalized() * max_speed + velocity_new.y = velocity_current.y + gravity * delta + + return velocity_new + func load_creature( filename ): self.creature = Creatures.Ra.new() @@ -42,7 +101,7 @@ func move_camera( p_translation ): $model/ra/spring_arm/camera.translate( p_translation ) func reset_camera(): - $model/ra/spring_arm.translation = Vector3( 0, 1.731, -1.74 ) + $model/ra/spring_arm.translation = Vector3( 0, 2, 2 ) $model/ra/spring_arm.rotation_degrees = Vector3( 0.0, 0.0, 0.0 ) $model/ra/spring_arm/camera.translation = Vector3( 0.0, 0.0, 0.0 ) - $model/ra/spring_arm/camera.rotation_degrees = Vector3( -14, -178.1, 0.328 ) + $model/ra/spring_arm/camera.rotation_degrees = Vector3( -14, 0, 0.328 ) diff --git a/scenes/player/player.tscn b/scenes/player/player.tscn index 826c7a0..6499ff9 100644 --- a/scenes/player/player.tscn +++ b/scenes/player/player.tscn @@ -6,6 +6,13 @@ [node name="player" type="Spatial"] script = ExtResource( 1 ) +[node name="camera" type="InterpolatedCamera" parent="."] +target = NodePath("../model/ra/camera_target") +speed = 5.0 +enabled = true + [node name="model" type="Spatial" parent="."] [node name="ra" parent="model" instance=ExtResource( 2 )] + +[editable path="model/ra"]