adding other player
This commit is contained in:
parent
460289025b
commit
c9340d55d6
8 changed files with 240 additions and 24 deletions
|
@ -4,13 +4,13 @@
|
|||
[ext_resource path="res://scenes/game/area_0_0.tscn" type="PackedScene" id=2]
|
||||
[ext_resource path="res://scenes/game/area_1_1.tscn" type="PackedScene" id=3]
|
||||
[ext_resource path="res://scenes/game/area_0_1.tscn" type="PackedScene" id=4]
|
||||
[ext_resource path="res://scenes/player/playerA.tscn" type="PackedScene" id=5]
|
||||
[ext_resource path="res://scenes/game/area_1_2.tscn" type="PackedScene" id=6]
|
||||
[ext_resource path="res://scenes/game/area_2_2.tscn" type="PackedScene" id=7]
|
||||
[ext_resource path="res://scenes/player/playerB.tscn" type="PackedScene" id=8]
|
||||
|
||||
[node name="spatial" type="Spatial"]
|
||||
|
||||
[node name="player" parent="." instance=ExtResource( 5 )]
|
||||
[node name="player" parent="." instance=ExtResource( 8 )]
|
||||
|
||||
[node name="area_0_0" parent="." instance=ExtResource( 2 )]
|
||||
|
||||
|
|
24
scenes/player/creature_raference.gd
Normal file
24
scenes/player/creature_raference.gd
Normal file
|
@ -0,0 +1,24 @@
|
|||
extends KinematicBody
|
||||
|
||||
# Declare member variables here. Examples:
|
||||
# var a = 2
|
||||
# var b = "text"
|
||||
|
||||
var rotation_speed_factor = 0.01
|
||||
var move_speed = 2.5
|
||||
var run_speed = 5.0
|
||||
var max_speed = 12.0
|
||||
export var gravity = -9.0
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
#func _process(delta):
|
||||
# pass
|
||||
|
||||
func get_animation_idle():
|
||||
return "_bip01_ca_female_idle"
|
22
scenes/player/creature_raference.tscn
Normal file
22
scenes/player/creature_raference.tscn
Normal file
|
@ -0,0 +1,22 @@
|
|||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://assets/creatures/raference/raference.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://scenes/player/creature_raference.gd" type="Script" id=2]
|
||||
|
||||
[sub_resource type="CylinderShape" id=1]
|
||||
radius = 0.2
|
||||
height = 0.1
|
||||
|
||||
[node name="spatial" type="KinematicBody"]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="collision_shape" type="CollisionShape" parent="."]
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="body" parent="collision_shape" instance=ExtResource( 1 )]
|
||||
|
||||
[node name="camera_tps" type="Camera" parent="."]
|
||||
transform = Transform( -1, 8.74228e-08, -5.0822e-21, 8.74228e-08, 1, -8.74228e-08, -7.64274e-15, -8.74228e-08, -1, 0, 1.23455, -1.8659 )
|
||||
|
||||
[node name="camera_fps" type="Camera" parent="."]
|
||||
transform = Transform( -1, 8.74228e-08, 0, 8.74228e-08, 1, -8.74228e-08, -7.64274e-15, -8.74228e-08, -1, 0, 1.5747, 0.453716 )
|
|
@ -4,7 +4,7 @@ signal new_focused_object( p_name )
|
|||
signal equip( p_slot, p_item )
|
||||
signal unequip( p_slot )
|
||||
|
||||
|
||||
var velocity: = Vector3.ZERO
|
||||
var mouse_delta = Vector2.ZERO
|
||||
var zoom_level = 0
|
||||
var camera_position = Vector3( 0.0, 2.0, -2.0 )
|
||||
|
@ -73,18 +73,54 @@ func _input( event ):
|
|||
# if $character.is_weapon_ready:
|
||||
# if event.is_action_pressed( "action_attack" ):
|
||||
# $character.attack()
|
||||
|
||||
|
||||
|
||||
|
||||
export var move_speed: = 5.0
|
||||
export var max_speed: = 12.0
|
||||
export var gravity = -100.0
|
||||
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
|
||||
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 _process( delta ):
|
||||
|
||||
$character.direction = self.get_input_direction()
|
||||
|
||||
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
|
||||
|
||||
# Rotation.
|
||||
if not Input.is_key_pressed( KEY_SHIFT ) and not $character.is_jump_started:
|
||||
$character.orientation = (Input.get_action_strength("move_turn_left") - Input.get_action_strength("move_turn_right"))
|
||||
else:
|
||||
$character.orientation = 0.0
|
||||
|
||||
# Movement
|
||||
velocity = self.calculate_velocity(velocity, move_direction, delta)
|
||||
velocity = $creature.move_and_slide(velocity, Vector3.UP, true)
|
||||
# move_and_slide(velocity, Vector3.UP, true)
|
||||
|
||||
# Camera.
|
||||
if not self.mouse_delta == Vector2.ZERO and self.camera_tps.current:
|
||||
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
|
@ -135,6 +171,7 @@ func _physics_process(delta):
|
|||
self.camera_tps.translation = self.camera_position
|
||||
# self.camera_tps.look_at( $character/look_at.global_transform.origin, Vector3( 0.0, 1.0, 0.0) )
|
||||
|
||||
#velocity = move_and_slide(velocity, Vector3.UP)
|
||||
|
||||
func interact( p_object = null ):
|
||||
if p_object and p_object.has_method( "interact" ):
|
||||
|
|
|
@ -40,9 +40,9 @@ func _ready():
|
|||
_:
|
||||
idle_animation = "idle"
|
||||
self.change_creature( "res://scenes/creature_creation/arche.tscn" )
|
||||
# search_animation($kinematic_body)
|
||||
# search_animation($character)
|
||||
# Globals.player['blend_shape']
|
||||
update_blend_shapes($kinematic_body/creature, Globals.player['blend_shape'])
|
||||
update_blend_shapes($character/creature, Globals.player['blend_shape'])
|
||||
animation_object.play( idle_animation )
|
||||
animation_object.connect("animation_finished", self, "_on_AnimationPlayer_animation_finished")
|
||||
|
||||
|
@ -74,8 +74,10 @@ func calculate_velocity(
|
|||
|
||||
|
||||
func _process( delta ):
|
||||
|
||||
#$character.direction = self.get_input_direction()
|
||||
Config.msg_info( Input.get_action_strength("move_backward") )
|
||||
Config.msg_info( Input.get_action_strength("move_forward") )
|
||||
# $character.direction = self.get_input_direction()
|
||||
#self.direction = self.get_input_direction()
|
||||
self.rotate_y( self.rotation_speed_factor * self.orientation )
|
||||
|
||||
# var forwards: Vector3 = 1.0 * direction.z
|
||||
|
@ -88,7 +90,7 @@ func _process( delta ):
|
|||
# move_direction.y = 0
|
||||
# velocity = self.calculate_velocity(velocity, move_direction, delta)
|
||||
## $creature.move_and_slide(velocity, Vector3.UP, true)
|
||||
# velocity = $kinematic_body.move_and_slide(velocity, Vector3.UP, true)
|
||||
# velocity = $character.move_and_slide(velocity, Vector3.UP, true)
|
||||
|
||||
|
||||
func _input( event ):
|
||||
|
@ -99,7 +101,7 @@ func _input( event ):
|
|||
else:
|
||||
self.orientation = 0.0
|
||||
if event is InputEventMouseMotion and Input.is_mouse_button_pressed( 2 ):
|
||||
if $kinematic_body/creature:
|
||||
if $character/creature:
|
||||
self.rotate_y( event.relative.x *0.01 )
|
||||
elif event.is_action( "camera_zoom_in" ):
|
||||
# self.zoom_level += 1
|
||||
|
@ -129,16 +131,16 @@ func _input( event ):
|
|||
|
||||
|
||||
func change_creature( new_model_path ):
|
||||
if $kinematic_body/creature:
|
||||
var old_model = $kinematic_body/creature
|
||||
$kinematic_body.remove_child( old_model )
|
||||
if $character/creature:
|
||||
var old_model = $character/creature
|
||||
$character.remove_child( old_model )
|
||||
old_model.queue_free()
|
||||
self.animation_object = null
|
||||
var new_model = load( new_model_path )
|
||||
if new_model:
|
||||
new_model = new_model.instance()
|
||||
new_model.name = "creature"
|
||||
$kinematic_body.add_child( new_model )
|
||||
$character.add_child( new_model )
|
||||
#new_model.connect( "animation_finished", self, "_on_creature_animation_finished" )
|
||||
# new_model.duplicate_meshes()
|
||||
search_animation( new_model )
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
[gd_scene load_steps=5 format=2]
|
||||
[gd_scene load_steps=4 format=2]
|
||||
|
||||
[ext_resource path="res://assets/creatures/arche/arche.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://scenes/player/playerA.gd" type="Script" id=2]
|
||||
[ext_resource path="res://assets/creatures/raference/raference.tscn" type="PackedScene" id=3]
|
||||
|
||||
|
@ -9,16 +8,13 @@
|
|||
[node name="player" type="Spatial"]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="kinematic_body" type="KinematicBody" parent="."]
|
||||
[node name="character" type="KinematicBody" parent="."]
|
||||
|
||||
[node name="creature" parent="kinematic_body" instance=ExtResource( 3 )]
|
||||
[node name="creature" parent="character" instance=ExtResource( 3 )]
|
||||
|
||||
[node name="creature_2" parent="kinematic_body" instance=ExtResource( 1 )]
|
||||
visible = false
|
||||
[node name="area" type="Area" parent="character"]
|
||||
|
||||
[node name="area" type="Area" parent="kinematic_body"]
|
||||
|
||||
[node name="collision_shape" type="CollisionShape" parent="kinematic_body/area"]
|
||||
[node name="collision_shape" type="CollisionShape" parent="character/area"]
|
||||
shape = SubResource( 1 )
|
||||
|
||||
[node name="camera_tps" type="Camera" parent="."]
|
||||
|
|
126
scenes/player/playerB.gd
Normal file
126
scenes/player/playerB.gd
Normal file
|
@ -0,0 +1,126 @@
|
|||
extends Spatial
|
||||
|
||||
var animation_object:AnimationPlayer = null
|
||||
var rotation_speed_factor = 0.01
|
||||
var orientation = 0.0
|
||||
var direction = Vector3.ZERO
|
||||
export var gravity = -9.0
|
||||
|
||||
func search_animation( obj ) -> bool:
|
||||
var ret:bool = false
|
||||
for i in obj.get_children():
|
||||
if i.get_name() == "AnimationPlayer":
|
||||
animation_object = i
|
||||
return true
|
||||
else:
|
||||
ret = search_animation(i)
|
||||
if ret == true:
|
||||
return ret
|
||||
return false
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
|
||||
func _ready():
|
||||
match Globals.player['Race']:
|
||||
"arche":
|
||||
self.change_creature( "res://scenes/player/creature_raference.tscn" )
|
||||
"isidor":
|
||||
self.change_creature( "res://scenes/player/creature_raference.tscn" )
|
||||
"raference":
|
||||
self.change_creature( "res://scenes/player/creature_raference.tscn" )
|
||||
_:
|
||||
self.change_creature( "res://scenes/player/creature_raference.tscn" )
|
||||
# search_animation($character)
|
||||
# Globals.player['blend_shape']
|
||||
update_blend_shapes($creature, Globals.player['blend_shape'])
|
||||
var idlename = "idle"
|
||||
if $creature.has_method("get_animation_idle"):
|
||||
idlename = $creature.get_animation_idle()
|
||||
self.rotation_speed_factor = $creature.rotation_speed_factor
|
||||
animation_object.play( idlename )
|
||||
animation_object.connect("animation_finished", self, "_on_AnimationPlayer_animation_finished")
|
||||
|
||||
|
||||
func _on_AnimationPlayer_animation_finished(anim_name):
|
||||
Config.msg_debug("Animation finished:" + anim_name)
|
||||
animation_object.play( anim_name )
|
||||
|
||||
|
||||
func change_creature( new_model_path ):
|
||||
if $creature:
|
||||
var old_model = $creature
|
||||
self.remove_child( old_model )
|
||||
old_model.queue_free()
|
||||
self.animation_object = null
|
||||
var new_model = load( new_model_path )
|
||||
if new_model:
|
||||
new_model = new_model.instance()
|
||||
new_model.name = "creature"
|
||||
self.add_child( new_model )
|
||||
#new_model.connect( "animation_finished", self, "_on_creature_animation_finished" )
|
||||
# new_model.duplicate_meshes()
|
||||
search_animation( new_model )
|
||||
|
||||
|
||||
func update_blend_shapes( obj , param):
|
||||
#blend_shapes = {}
|
||||
update_blend_shapes_step(obj, param, "")
|
||||
pass
|
||||
|
||||
|
||||
func update_blend_shapes_step( obj, param, father = "" ):
|
||||
for i in obj.get_children():
|
||||
var root = father + str(i.name) + "."
|
||||
if i is MeshInstance:
|
||||
for key in i.get_property_list():
|
||||
if key.name.substr(0, 13) == "blend_shapes/":
|
||||
var blend = key.name.substr(13)
|
||||
if param.has(blend):
|
||||
i.set( "blend_shapes/"+blend, param[blend] )
|
||||
update_blend_shapes_step( i, param, root)
|
||||
|
||||
|
||||
static func get_input_direction() -> Vector3:
|
||||
return Vector3(
|
||||
Input.get_action_strength("move_strafe_right") - Input.get_action_strength("move_strafe_left"),
|
||||
0,
|
||||
Input.get_action_strength("move_backward") - Input.get_action_strength("move_forward")
|
||||
)
|
||||
|
||||
|
||||
func _process( delta ):
|
||||
Config.msg_info( Input.get_action_strength("move_backward") )
|
||||
Config.msg_info( Input.get_action_strength("move_forward") )
|
||||
# $character.direction = self.get_input_direction()
|
||||
#self.direction = self.get_input_direction()
|
||||
self.direction = self.get_input_direction()
|
||||
self.rotate_y( self.rotation_speed_factor * self.orientation )
|
||||
|
||||
|
||||
|
||||
|
||||
func calculate_velocity(
|
||||
velocity_current: Vector3,
|
||||
move_direction: Vector3,
|
||||
delta: float
|
||||
) -> Vector3:
|
||||
var velocity_new = Vector3.ZERO
|
||||
velocity_new = move_direction
|
||||
|
||||
velocity_new *= $creature.move_speed
|
||||
if velocity_new.length() > $creature.max_speed:
|
||||
velocity_new = velocity_new.normalized() * $creature.max_speed
|
||||
velocity_new.y = velocity_current.y + gravity * delta
|
||||
return velocity_new
|
||||
|
||||
|
||||
func _input( event ):
|
||||
# Config.msg_debug(str(event))
|
||||
self.direction = self.get_input_direction()
|
||||
if not Input.is_key_pressed( KEY_SHIFT ):
|
||||
self.orientation = (Input.get_action_strength("move_turn_left") - Input.get_action_strength("move_turn_right"))
|
||||
else:
|
||||
self.orientation = 0.0
|
||||
if event is InputEventMouseMotion and Input.is_mouse_button_pressed( 2 ):
|
||||
if $creature:
|
||||
self.rotate_y( event.relative.x *0.01 )
|
9
scenes/player/playerB.tscn
Normal file
9
scenes/player/playerB.tscn
Normal file
|
@ -0,0 +1,9 @@
|
|||
[gd_scene load_steps=3 format=2]
|
||||
|
||||
[ext_resource path="res://scenes/player/creature_raference.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://scenes/player/playerB.gd" type="Script" id=2]
|
||||
|
||||
[node name="player" type="Spatial"]
|
||||
script = ExtResource( 2 )
|
||||
|
||||
[node name="creature" parent="." instance=ExtResource( 1 )]
|
Loading…
Reference in a new issue