Implement throwing.
This commit is contained in:
		
							parent
							
								
									8b6cae07c8
								
							
						
					
					
						commit
						e8fc5b600c
					
				| 
						 | 
				
			
			@ -1,4 +1,4 @@
 | 
			
		|||
[gd_scene load_steps=29 format=3 uid="uid://blpbgwklc21k5"]
 | 
			
		||||
[gd_scene load_steps=30 format=3 uid="uid://blpbgwklc21k5"]
 | 
			
		||||
 | 
			
		||||
[ext_resource type="Script" uid="uid://jshmfmeoj28y" path="res://characters/base/character.gd" id="1_f78fl"]
 | 
			
		||||
[ext_resource type="Script" uid="uid://vogde76hsl0j" path="res://characters/base/character_state_properties.gd" id="2_cchsv"]
 | 
			
		||||
| 
						 | 
				
			
			@ -28,6 +28,7 @@
 | 
			
		|||
[ext_resource type="Resource" uid="uid://cgx3p61bbw6sw" path="res://characters/base/template_csp_jump_while_holding.tres" id="23_hhowv"]
 | 
			
		||||
[ext_resource type="Resource" uid="uid://dc346050qtltb" path="res://characters/base/template_csp_swim.tres" id="24_0pfk6"]
 | 
			
		||||
[ext_resource type="Resource" uid="uid://mgefvwuayfk4" path="res://characters/base/template_csp_swim_while_holding.tres" id="25_hpxkk"]
 | 
			
		||||
[ext_resource type="Resource" uid="uid://bgunca0v4g3jg" path="res://characters/base/template_csp_throw.tres" id="26_5etud"]
 | 
			
		||||
 | 
			
		||||
[node name="BaseCharacter" type="RigidBody3D" node_paths=PackedStringArray("_audio_player", "_property_save_restore_stack", "_state_machine")]
 | 
			
		||||
mass = 60.0
 | 
			
		||||
| 
						 | 
				
			
			@ -54,6 +55,7 @@ _state_properties = Dictionary[StringName, ExtResource("2_cchsv")]({
 | 
			
		|||
&"sprint": ExtResource("6_aigsb"),
 | 
			
		||||
&"swim": ExtResource("24_0pfk6"),
 | 
			
		||||
&"swim-while-holding": ExtResource("25_hpxkk"),
 | 
			
		||||
&"throw": ExtResource("26_5etud"),
 | 
			
		||||
&"victory1": ExtResource("15_hhowv"),
 | 
			
		||||
&"victory2": ExtResource("16_0pfk6"),
 | 
			
		||||
&"walk": ExtResource("4_0mnbh"),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -755,6 +755,25 @@ func _apply_jump_deceleration(delta: float) -> void:
 | 
			
		|||
		_get_jump_deceleration()*delta
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
func _pick_up_deferred_callback(what: Node3D) -> void:
 | 
			
		||||
	if _carrying == what:
 | 
			
		||||
		if what is RigidBody3D:
 | 
			
		||||
			what.linear_velocity = Vector3.ZERO
 | 
			
		||||
			what.angular_velocity = Vector3.ZERO
 | 
			
		||||
		what.process_mode = PROCESS_MODE_DISABLED
 | 
			
		||||
		what.reparent(self)
 | 
			
		||||
 | 
			
		||||
func _put_down_deferred_callback(what: Node3D) -> void:
 | 
			
		||||
	what.reparent(get_parent())
 | 
			
		||||
	what.process_mode = PROCESS_MODE_INHERIT
 | 
			
		||||
 | 
			
		||||
func _throw_deferred_callback(what: Node3D) -> void:
 | 
			
		||||
	_put_down_deferred_callback(what)
 | 
			
		||||
	if what is RigidBody3D:
 | 
			
		||||
		what.linear_velocity = 1.5*linear_velocity.length()*knockback*(
 | 
			
		||||
			(ground_normal/2.0 - global_basis.z).normalized()
 | 
			
		||||
		)
 | 
			
		||||
 | 
			
		||||
#endregion
 | 
			
		||||
 | 
			
		||||
#region Public Methods
 | 
			
		||||
| 
						 | 
				
			
			@ -1036,6 +1055,7 @@ func _make_state_handler_descriptors() -> Dictionary[StringName, Variant]:
 | 
			
		|||
			&'ticked': _on_put_down_state_tick,
 | 
			
		||||
			&'stopped': _on_put_down_state_stop
 | 
			
		||||
		},
 | 
			
		||||
		&'throw': _on_throw_state_tick,
 | 
			
		||||
		&'idle-while-holding': _on_idle_while_holding_state_tick,
 | 
			
		||||
		&'walk-while-holding': _on_walk_while_holding_state_tick,
 | 
			
		||||
		&'run-while-holding': _on_run_while_holding_state_tick,
 | 
			
		||||
| 
						 | 
				
			
			@ -1199,21 +1219,12 @@ func _on_put_down_state_tick(delta: float) -> void:
 | 
			
		|||
 | 
			
		||||
func _on_put_down_state_stop() -> void:
 | 
			
		||||
	if _carrying:
 | 
			
		||||
		var thunk := func (what: Node3D) -> void:
 | 
			
		||||
			what.reparent(get_parent())
 | 
			
		||||
			what.process_mode = PROCESS_MODE_INHERIT
 | 
			
		||||
		thunk.call_deferred(_carrying)
 | 
			
		||||
		call_deferred(&'_put_down_deferred_callback', _carrying)
 | 
			
		||||
		_carrying = null
 | 
			
		||||
 | 
			
		||||
func _on_pick_up_state_start() -> void:
 | 
			
		||||
	if _carrying:
 | 
			
		||||
		var thunk := func (what: Node3D) -> void:
 | 
			
		||||
			if _carrying == what:
 | 
			
		||||
				if what is RigidBody3D:
 | 
			
		||||
					what.linear_velocity = Vector3.ZERO
 | 
			
		||||
					what.angular_velocity = Vector3.ZERO
 | 
			
		||||
				what.process_mode = PROCESS_MODE_DISABLED
 | 
			
		||||
				what.reparent(self)
 | 
			
		||||
		thunk.call_deferred(_carrying)
 | 
			
		||||
		call_deferred(&'_pick_up_deferred_callback', _carrying)
 | 
			
		||||
	else:
 | 
			
		||||
		force_change_state(&'idle')
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1274,6 +1285,8 @@ func _on_run_while_holding_state_tick(delta: float) -> void:
 | 
			
		|||
		force_change_state(&'jump-while-holding')
 | 
			
		||||
	elif top_speed_proximity < 0.125:
 | 
			
		||||
		state = &'walk-while-holding'
 | 
			
		||||
	elif action1_impetus || action2_impetus || interact_impetus:
 | 
			
		||||
		state = &'throw'
 | 
			
		||||
 | 
			
		||||
func _on_jump_while_holding_state_start() -> void:
 | 
			
		||||
	_apply_jump_impulse()
 | 
			
		||||
| 
						 | 
				
			
			@ -1287,12 +1300,16 @@ func _on_jump_while_holding_state_tick(delta: float) -> void:
 | 
			
		|||
		state = &'run-while-holding'
 | 
			
		||||
	elif linear_velocity.dot(ground_normal) <= -0.25:
 | 
			
		||||
		state = &'fall-while-holding'
 | 
			
		||||
	elif action1_impetus || action2_impetus || interact_impetus:
 | 
			
		||||
		state = &'throw'
 | 
			
		||||
 | 
			
		||||
func _on_fall_while_holding_state_tick(delta: float) -> void:
 | 
			
		||||
	_do_standard_motion(delta)
 | 
			
		||||
	if is_really_grounded() && !state_coyote_time_active():
 | 
			
		||||
		play_sound(_landing_sound, _landing_sound_volume_db)
 | 
			
		||||
		state = &'run-while-holding'
 | 
			
		||||
	elif action1_impetus || action2_impetus || interact_impetus:
 | 
			
		||||
		state = &'throw'
 | 
			
		||||
 | 
			
		||||
func _on_swim_state_tick(delta: float) -> void:
 | 
			
		||||
	_do_standard_motion(delta)
 | 
			
		||||
| 
						 | 
				
			
			@ -1300,4 +1317,17 @@ func _on_swim_state_tick(delta: float) -> void:
 | 
			
		|||
func _on_swim_while_holding_state_tick(delta: float) -> void:
 | 
			
		||||
	_do_standard_motion(delta)
 | 
			
		||||
 | 
			
		||||
func _on_throw_state_tick(_delta: float) -> void:
 | 
			
		||||
	if _state_animation_done():
 | 
			
		||||
		if _carrying:
 | 
			
		||||
			_put_down_without_animation()
 | 
			
		||||
		_carrying = null
 | 
			
		||||
		force_change_state(&'run')
 | 
			
		||||
	elif _carrying && (
 | 
			
		||||
		_anim_player.current_animation_position /
 | 
			
		||||
		_anim_player.current_animation_length
 | 
			
		||||
	) >= 0.5:
 | 
			
		||||
		call_deferred(&'_throw_deferred_callback', _carrying)
 | 
			
		||||
		_carrying = null
 | 
			
		||||
 | 
			
		||||
#endregion
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,33 @@
 | 
			
		|||
[gd_resource type="Resource" script_class="CharacterStateProperties" load_steps=3 format=3 uid="uid://bgunca0v4g3jg"]
 | 
			
		||||
 | 
			
		||||
[ext_resource type="Script" uid="uid://vogde76hsl0j" path="res://characters/base/character_state_properties.gd" id="1_lxcu1"]
 | 
			
		||||
[ext_resource type="AudioStream" uid="uid://b75p1mryrkduo" path="res://audio/small_whoosh.ogg" id="1_yqaif"]
 | 
			
		||||
 | 
			
		||||
[resource]
 | 
			
		||||
script = ExtResource("1_lxcu1")
 | 
			
		||||
use_coyote_time = false
 | 
			
		||||
coyote_time = 0.0
 | 
			
		||||
uninterruptible = true
 | 
			
		||||
is_carrying_state = true
 | 
			
		||||
equivalent_carrying_state = &""
 | 
			
		||||
animation_name = &"throw"
 | 
			
		||||
animation_alt_name = &""
 | 
			
		||||
animation_base_speed = 1.0
 | 
			
		||||
animation_blend_time = 0.25
 | 
			
		||||
animation_speedup_with_velocity = 0.0
 | 
			
		||||
audio = ExtResource("1_yqaif")
 | 
			
		||||
audio_volume_db = 0.0
 | 
			
		||||
collider_length = 1.0
 | 
			
		||||
collider_radius = 0.5
 | 
			
		||||
collider_horizontal = false
 | 
			
		||||
yaw_orientation = 0
 | 
			
		||||
pitch_orientation = 3
 | 
			
		||||
orientation_speed = 600.0
 | 
			
		||||
counts_as_grounded = true
 | 
			
		||||
physics_mode = 2
 | 
			
		||||
is_attack = false
 | 
			
		||||
attack_base_damage = 0.0
 | 
			
		||||
attack_base_knockback = 0.0
 | 
			
		||||
invulnerable = false
 | 
			
		||||
etc = Dictionary[String, Variant]({})
 | 
			
		||||
metadata/_custom_type_script = "uid://vogde76hsl0j"
 | 
			
		||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							| 
						 | 
				
			
			@ -0,0 +1,14 @@
 | 
			
		|||
class_name ExtMath extends StaticClass
 | 
			
		||||
 | 
			
		||||
static func multilerp(control_points: Array, weight: float) -> Variant:
 | 
			
		||||
	if control_points.is_empty():
 | 
			
		||||
		return null
 | 
			
		||||
	elif control_points.size() == 1:
 | 
			
		||||
		return control_points[0]
 | 
			
		||||
	else:
 | 
			
		||||
		var offset: float = weight*(control_points.size() - 1)
 | 
			
		||||
		return lerp(
 | 
			
		||||
			control_points[floori(offset)],
 | 
			
		||||
			control_points[ceili(offset)],
 | 
			
		||||
			fposmod(offset, 1.0)
 | 
			
		||||
		)
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
uid://cnhaxbhw8cd5v
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
class_name StaticClass extends Object
 | 
			
		||||
 | 
			
		||||
func _init() -> void:
 | 
			
		||||
	push_error(
 | 
			
		||||
		"%s is an instance of a static class, which is not allowed" %
 | 
			
		||||
		self
 | 
			
		||||
	)
 | 
			
		||||
	free()
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
uid://bwdm51eupfb5n
 | 
			
		||||
		Loading…
	
		Reference in New Issue