EDIT changement de la methode de deplacement du personnage et diverse bricoles

This commit is contained in:
osquallo 2020-03-27 12:43:49 +01:00
parent a80cdba5eb
commit 5dbf4b3f0a
11 changed files with 278 additions and 27 deletions

View file

@ -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;
// }
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

View file

@ -8,9 +8,50 @@
config_version=4 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={ _global_script_class_icons={
"CameraRig": "",
"CameraState": "",
"Mannequiny": "",
"Player": "",
"PlayerState": "",
"State": "",
"StateMachine": ""
} }
[application] [application]

View file

@ -6,11 +6,13 @@ export(bool) var gravity_enabled = true
var creature = null var creature = null
func _process( delta ): var is_moving = false
if self.gravity_enabled and $model:
for child in $model.get_children(): #func _process( delta ):
if child is KinematicBody: # if self.gravity_enabled and $model:
child.move_and_slide( Vector3( 0.0, -9.81, 0.0 ), Vector3( 0.0, 1.0, 0.0 ), true ) # 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 ): 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.rotate( Vector3( 0.0, 1.0, 0.0 ), child.rotation.y )
spatial.translate( m_movment ) spatial.translate( m_movment )
child.move_and_slide( spatial.translation*10.0, Vector3( 0.0, 1.0, 0.0 ), true ) 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 ): func turn( m_rotation ):
if $model: if $model:

View file

@ -11,16 +11,20 @@ height = 0.827082
[node name="ra" type="KinematicBody"] [node name="ra" type="KinematicBody"]
[node name="spring_arm" type="Spatial" parent="."] [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"] [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 )] [node name="model_static" parent="." instance=ExtResource( 1 )]
visible = false visible = false
[node name="model" parent="." instance=ExtResource( 2 )] [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="."] [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 ) transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0.808348, 0 )
shape = SubResource( 1 ) 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 )

View file

@ -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")

View file

@ -16,22 +16,25 @@ var heightmap = null
func _input( event ): func _input( event ):
var movment = Vector3( 0.0, 0.0, 0.0 ) var movment = Vector3( 0.0, 0.0, 0.0 )
var rotation = Vector3( 0.0, 0.0, 0.0 ) var rotation = Vector3( 0.0, 0.0, 0.0 )
if event.is_action( "move_forward" ): $creatures/player.is_moving = false
movment.z += self.player_speed if event.is_action( "move_forward" ) and event.is_pressed():
elif event.is_action( "move_backward" ): movment.z += self.player_speed * Input.get_action_strength("move_forward")
movment.z -= self.player_speed $creatures/player.is_moving = true
elif event.is_action( "move_left" ): 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 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 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 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 rotation.y -= self.player_rotation_speed
$creatures/player.turn( rotation ) # $creatures/player.turn( rotation )
$creatures/player.move( movment ) # $creatures/player.move( movment )
if event.is_action( "zoom_in" ): if event.is_action( "zoom_in" ):
self.camera_zoom -= self.camera_zoom_speed self.camera_zoom -= self.camera_zoom_speed
@ -56,12 +59,15 @@ func _process( delta ):
# $camera_base.translate( camera_translation ) # $camera_base.translate( camera_translation )
# camera_translation = Vector3() # camera_translation = Vector3()
# $camera_base.rotate( Vector3( 0.0, 1.0, 0.0 ), deg2rad( camera_rotation ) ) # $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.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.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 # camera_rotation = 0.0
self.camera_zoom = 0.0 self.camera_zoom = 0.0
self.mouse_delta = Vector2( 0.0, 0.0 ) self.mouse_delta = Vector2( 0.0, 0.0 )

View file

@ -23,8 +23,8 @@ noise = SubResource( 1 )
[sub_resource type="ShaderMaterial" id=3] [sub_resource type="ShaderMaterial" id=3]
resource_local_to_scene = true resource_local_to_scene = true
shader = ExtResource( 5 ) shader = ExtResource( 5 )
shader_param/iTime = 6560.62 shader_param/iTime = 1.16881
shader_param/iFrame = 391307 shader_param/iFrame = 78
shader_param/COVERAGE = 0.5 shader_param/COVERAGE = 0.5
shader_param/THICKNESS = 25.0 shader_param/THICKNESS = 25.0
shader_param/ABSORPTION = 1.031 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="creatures" type="Spatial" parent="."]
[node name="player" parent="creatures" instance=ExtResource( 1 )] [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="."] [node name="mist_fx" type="MeshInstance" parent="."]
cast_shadow = 0 cast_shadow = 0

View file

@ -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"]

View file

@ -1,12 +1,71 @@
extends "res://ressources/scripts/entity.gd" 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(): func _ready():
# $camera.make_current()
$model/ra/spring_arm/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 ): func load_creature( filename ):
self.creature = Creatures.Ra.new() self.creature = Creatures.Ra.new()
@ -42,7 +101,7 @@ func move_camera( p_translation ):
$model/ra/spring_arm/camera.translate( p_translation ) $model/ra/spring_arm/camera.translate( p_translation )
func reset_camera(): 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.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.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 )

View file

@ -6,6 +6,13 @@
[node name="player" type="Spatial"] [node name="player" type="Spatial"]
script = ExtResource( 1 ) 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="model" type="Spatial" parent="."]
[node name="ra" parent="model" instance=ExtResource( 2 )] [node name="ra" parent="model" instance=ExtResource( 2 )]
[editable path="model/ra"]