mirror of
https://port.numenaute.org/aleajactaest/khanat-client.git
synced 2024-11-09 08:49:05 +00:00
133 lines
5 KiB
GDScript
133 lines
5 KiB
GDScript
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 sprint_speed = 10.0
|
|
export var max_speed: = 12.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
|
|
var _is_sprinting = false
|
|
|
|
func _ready():
|
|
# $camera.make_current()
|
|
$model/ra/spring_arm/camera.make_current()
|
|
|
|
|
|
func _input( event ):
|
|
|
|
if event.is_action_pressed( "toggle_sprint" ):
|
|
self._is_sprinting = not self._is_sprinting
|
|
|
|
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 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" )
|
|
|
|
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
|
|
if self.is_sprinting():
|
|
velocity_new *= sprint_speed
|
|
else:
|
|
velocity_new *= 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_old.new()
|
|
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 )
|
|
|
|
func is_sprinting():
|
|
if (not self._is_sprinting and Input.is_action_pressed( "sprint" )) \
|
|
or (self._is_sprinting and not Input.is_action_pressed( "sprint" )) \
|
|
:
|
|
return true
|
|
return false
|
|
|
|
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():
|
|
$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, 0, 0.328 )
|