1
Fork 0
mirror of https://github.com/Steffo99/pineapple-surf.git synced 2024-11-22 15:54:20 +00:00
pineapple-surf/player/onhand/BaseWeapon.gd

52 lines
1.1 KiB
GDScript3
Raw Normal View History

2023-01-08 17:39:37 +00:00
extends Node3D
class_name BaseWeapon
enum WeaponSlot {
ONE,
TWO,
THREE
}
2023-01-08 01:25:48 +00:00
enum AmmoType {
NONE,
SINGLE
}
2023-01-08 17:39:37 +00:00
@export_range(0,0.002) var MOUSE_MOVEMENT_BOB_AMOUNT := 0.002
var player: Player
var weaponSlot: WeaponSlot = WeaponSlot.ONE
2023-01-08 01:25:48 +00:00
var ammoType: AmmoType = AmmoType.NONE
2023-01-08 17:39:37 +00:00
var last_mouse_movement := Vector2.ZERO
var mouse_movements := [Vector2.ZERO] as Array[Vector2]
func on_switch_in():
pass
func on_switch_out():
pass
func bob_weapon(node: Node3D, delta: float):
2023-01-08 17:39:37 +00:00
if len(self.mouse_movements) >= 5:
self.mouse_movements.pop_front()
self.mouse_movements.push_back(Vector2(
self.last_mouse_movement.y * 0.05,
self.last_mouse_movement.x * 0.05
))
var avg_mvmt = self.mouse_movements \
.reduce(func(accum, number): return accum + number) \
/ len(self.mouse_movements) as Vector2
node.position = Vector3.ZERO.lerp(Vector3(
2023-01-08 17:39:37 +00:00
-avg_mvmt.y,
avg_mvmt.x,
0,
2023-01-08 17:39:37 +00:00
), MOUSE_MOVEMENT_BOB_AMOUNT / delta)
self.last_mouse_movement = Vector2.ZERO
func _input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
2023-01-08 17:39:37 +00:00
self.last_mouse_movement = event.relative