2020-03-21 09:10:26 +00:00
|
|
|
extends "res://ressources/scripts/entity.gd"
|
|
|
|
|
2020-03-27 11:43:49 +00:00
|
|
|
onready var player = $model/ra
|
|
|
|
onready var camera = $model/ra/spring_arm
|
|
|
|
onready var skin = $model/ra/model
|
2020-03-26 09:39:29 +00:00
|
|
|
|
2020-03-28 07:07:33 +00:00
|
|
|
export var sprint_speed = 10.0
|
|
|
|
export var max_speed: = 12.0
|
2020-03-27 11:43:49 +00:00
|
|
|
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
|
2020-03-28 07:44:06 +00:00
|
|
|
var _is_sprinting = false
|
2020-03-26 09:39:29 +00:00
|
|
|
|
2020-03-21 09:10:26 +00:00
|
|
|
func _ready():
|
2020-03-27 11:43:49 +00:00
|
|
|
# $camera.make_current()
|
2020-03-21 09:10:26 +00:00
|
|
|
$model/ra/spring_arm/camera.make_current()
|
|
|
|
|
2020-03-28 07:07:33 +00:00
|
|
|
|
|
|
|
func _input( event ):
|
|
|
|
|
|
|
|
if event.is_action_pressed( "toggle_sprint" ):
|
2020-03-28 07:44:06 +00:00
|
|
|
self._is_sprinting = not self._is_sprinting
|
2020-03-28 07:07:33 +00:00
|
|
|
|
2020-03-27 11:43:49 +00:00
|
|
|
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)
|
|
|
|
|
2020-03-28 07:07:33 +00:00
|
|
|
if input_direction:
|
|
|
|
if not input_direction.z == 0.0:
|
|
|
|
if self.is_sprinting():
|
|
|
|
$model/ra/model/AnimationPlayer.play( "run" )
|
|
|
|
else:
|
|
|
|
$model/ra/model/AnimationPlayer.play( "walk" )
|
|
|
|
elif input_direction.x > 0.0:
|
|
|
|
$model/ra/model/AnimationPlayer.play( "strafe_right" )
|
|
|
|
elif input_direction.x < 0.0:
|
|
|
|
$model/ra/model/AnimationPlayer.play( "strafe_left" )
|
|
|
|
|
2020-03-27 11:43:49 +00:00
|
|
|
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")
|
|
|
|
)
|
2020-03-21 09:10:26 +00:00
|
|
|
|
|
|
|
|
2020-03-27 11:43:49 +00:00
|
|
|
func calculate_velocity(
|
|
|
|
velocity_current: Vector3,
|
|
|
|
move_direction: Vector3,
|
|
|
|
delta: float
|
|
|
|
) -> Vector3:
|
2020-03-28 07:07:33 +00:00
|
|
|
var velocity_new := move_direction
|
|
|
|
if self.is_sprinting():
|
|
|
|
velocity_new *= sprint_speed
|
|
|
|
else:
|
|
|
|
velocity_new *= move_speed
|
2020-03-27 11:43:49 +00:00
|
|
|
if velocity_new.length() > max_speed:
|
|
|
|
velocity_new = velocity_new.normalized() * max_speed
|
|
|
|
velocity_new.y = velocity_current.y + gravity * delta
|
|
|
|
|
|
|
|
return velocity_new
|
|
|
|
|
2020-03-21 09:10:26 +00:00
|
|
|
func load_creature( filename ):
|
2020-03-26 09:39:29 +00:00
|
|
|
|
2020-03-29 11:29:57 +00:00
|
|
|
self.creature = Creatures.Ra_old.new()
|
2020-03-26 09:39:29 +00:00
|
|
|
self.creature.from_file( filename )
|
|
|
|
|
|
|
|
# # version statique.
|
|
|
|
# $model/ra/model/body.set( "blend_shapes/Boobs", self.creature.female_boobs )
|
|
|
|
# $model/ra/model/body.set( "blend_shapes/Female_hip", self.creature.female_hip )
|
|
|
|
# $model/ra/model/body.set( "blend_shapes/Male_Pack", self.creature.male_pack )
|
|
|
|
# $model/ra/model/body.set( "blend_shapes/Male_Throat", self.creature.male_throat )
|
|
|
|
# $model/ra/model/body.set( "blend_shapes/Pregnant", self.creature.female_pregnant )
|
|
|
|
# $model/ra/model/body.set( "blend_shapes/Pregnant", self.creature.female_pregnant )
|
|
|
|
# $model/ra/model/body.get_surface_material( 0 ).set_shader_param( "albedo", self.creature.color )
|
|
|
|
#
|
|
|
|
# Version animée.
|
|
|
|
$model/ra/model/metarig/Skeleton/body.set( "blend_shapes/Boobs", self.creature.female_boobs )
|
|
|
|
$model/ra/model/metarig/Skeleton/body.set( "blend_shapes/Female_hip", self.creature.female_hip )
|
|
|
|
$model/ra/model/metarig/Skeleton/body.set( "blend_shapes/Male_Pack", self.creature.male_pack )
|
|
|
|
$model/ra/model/metarig/Skeleton/body.set( "blend_shapes/Male_Throat", self.creature.male_throat )
|
|
|
|
$model/ra/model/metarig/Skeleton/body.set( "blend_shapes/Pregnant", self.creature.female_pregnant )
|
|
|
|
$model/ra/model/metarig/Skeleton/body.set( "blend_shapes/Pregnant", self.creature.female_pregnant )
|
|
|
|
$model/ra/model/metarig/Skeleton/body.get_surface_material( 0 ).set_shader_param( "albedo", self.creature.color )
|
2020-03-21 09:10:26 +00:00
|
|
|
|
2020-03-28 07:07:33 +00:00
|
|
|
func is_sprinting():
|
2020-03-28 07:44:06 +00:00
|
|
|
if (not self._is_sprinting and Input.is_action_pressed( "sprint" )) \
|
|
|
|
or (self._is_sprinting and not Input.is_action_pressed( "sprint" )) \
|
2020-03-28 07:07:33 +00:00
|
|
|
:
|
|
|
|
return true
|
|
|
|
return false
|
2020-03-24 18:48:58 +00:00
|
|
|
|
|
|
|
func rotate_camera_arm( p_axis, p_angle_degree ):
|
|
|
|
$model/ra/spring_arm.rotate( p_axis, p_angle_degree )
|
|
|
|
|
|
|
|
func rotate_camera( p_axis, p_angle_degree ):
|
|
|
|
$model/ra/spring_arm/camera.rotate( p_axis, p_angle_degree )
|
|
|
|
|
|
|
|
func move_camera( p_translation ):
|
|
|
|
$model/ra/spring_arm/camera.translate( p_translation )
|
|
|
|
|
|
|
|
func reset_camera():
|
2020-03-27 11:43:49 +00:00
|
|
|
$model/ra/spring_arm.translation = Vector3( 0, 2, 2 )
|
2020-03-24 18:48:58 +00:00
|
|
|
$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 )
|
2020-03-27 11:43:49 +00:00
|
|
|
$model/ra/spring_arm/camera.rotation_degrees = Vector3( -14, 0, 0.328 )
|