точно есть дэшм
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
extends Node3D
|
||||
|
||||
var cW
|
||||
var cWModel : Node3D
|
||||
|
||||
# Безопасные относительные пути к телу моба, родителю и плееру анимаций
|
||||
@onready var mob_body : CharacterBody3D = $"../.."
|
||||
@onready var animPlayer : AnimationPlayer = $"../.."/AnimationPlayer
|
||||
@onready var weaponManager : Node3D = $".."
|
||||
|
||||
func getCurrentWeapon(currWeap, currweaponManagerodel):
|
||||
cW = currWeap
|
||||
cWModel = currweaponManagerodel
|
||||
|
||||
func _process(delta: float):
|
||||
if cW != null and cWModel != null and is_instance_valid(mob_body) and animPlayer != null:
|
||||
# КРИТИЧЕСКАЯ ЗАЩИТА ВСПЫШКИ: Если играет выстрел, код НЕ перекрывает координаты своей математикой!
|
||||
if animPlayer.is_playing() and animPlayer.current_animation == "ShootAnimPistol":
|
||||
return
|
||||
|
||||
# Если выстрела нет, плавно покачиваем и наклоняем пистолет при движении моба
|
||||
var movement_dir = mob_body.velocity.normalized()
|
||||
weaponTilt(movement_dir, delta)
|
||||
weaponBob(mob_body.velocity.length(), delta)
|
||||
|
||||
func weaponTilt(moveDir, delta):
|
||||
if "tiltRotAmount" in cW and "tiltRotSpeed" in cW:
|
||||
cWModel.rotation.z = lerp(cWModel.rotation.z, moveDir.x * cW.tiltRotAmount, cW.tiltRotSpeed * delta)
|
||||
|
||||
func weaponBob(vel : float, delta):
|
||||
if not ("bobFreq" in cW) or not ("bobAmount" in cW) or not ("bobSpeed" in cW): return
|
||||
var bobFreq : float = cW.bobFreq
|
||||
|
||||
if vel < 1.0:
|
||||
if "onIdleBobFreqDivider" in cW: bobFreq /= cW.onIdleBobFreqDivider
|
||||
else: bobFreq /= 2.0
|
||||
|
||||
var secure_vel = clamp(vel, 0.0, 10.0)
|
||||
if secure_vel < 0.2: secure_vel = 0.5
|
||||
|
||||
var time_tick = Time.get_ticks_msec() * bobFreq
|
||||
var target_y = cW.bobPos.y + sin(time_tick) * cW.bobAmount * secure_vel / 10
|
||||
var target_x = cW.bobPos.x + sin(time_tick * 0.5) * cW.bobAmount * secure_vel / 10
|
||||
|
||||
if is_finite(target_y) and is_finite(target_x):
|
||||
cWModel.position.y = lerp(cWModel.position.y, target_y, cW.bobSpeed * delta)
|
||||
cWModel.position.x = lerp(cWModel.position.x, target_x, cW.bobSpeed * delta)
|
||||
|
||||
# Резервная функция вызова
|
||||
func playAnimation(animName : String, animSpeed : float, hasToRestartAnim : bool):
|
||||
if animPlayer != null:
|
||||
if hasToRestartAnim and animPlayer.current_animation == animName:
|
||||
animPlayer.seek(0, true)
|
||||
animPlayer.play("%s" % animName, -1, animSpeed)
|
||||
Reference in New Issue
Block a user