Added spread for weapons

This commit is contained in:
2025-02-04 18:35:44 +03:00
parent 3e6eab08fd
commit b4da54c2ac
6 changed files with 66 additions and 10 deletions

View File

@ -0,0 +1,35 @@
class_name BulletSpread extends Resource
@export var max_spread: float = 5.0
@export var spread_increase_per_shot: float = 0.5
var current_spread: float = 0.0
var shot_count: int = 0
var spread_y : float = 0
var spread_x: float = 0
var last_y_spread: float = 0 # remember y cord for 9th shot
func reset_spread() -> void:
current_spread = 0.0
shot_count = 0
# To get offset for current shot
func get_spread_offset() -> Vector3:
# Increasing spread after each shot
current_spread = min(current_spread + spread_increase_per_shot, max_spread)
shot_count += 1
# If its a 1 shot
if shot_count == 1:
return Vector3.ZERO
if shot_count < 10:
spread_x = randf_range(-current_spread, current_spread) * (shot_count - 1)
spread_y = current_spread * (shot_count - 1)
if shot_count == 9: last_y_spread = spread_y
else:
spread_x = randf_range(-current_spread, current_spread) * 10
spread_y = randf_range(last_y_spread - 10, last_y_spread + 10)
return Vector3(spread_x, spread_y, 0)

View File

@ -1,7 +1,8 @@
[gd_scene load_steps=55 format=4 uid="uid://dtvo21mk1webd"]
[gd_scene load_steps=56 format=4 uid="uid://dtvo21mk1webd"]
[ext_resource type="PackedScene" uid="uid://dab7jttp7ywfh" path="res://scenes/weapon/guns/ak/gun.tscn" id="1_aaafm"]
[ext_resource type="Script" path="res://scenes/weapon/generic_weapon_controller.gd" id="1_h1xyo"]
[ext_resource type="Script" path="res://scenes/weapon/guns/ak/bullet_spread.gd" id="2_4o3my"]
[ext_resource type="PackedScene" uid="uid://bjyltbtx45cqs" path="res://scenes/weapon/misc/bullet_trace_distance.tscn" id="3_5ff4y"]
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_tg27p"]
@ -555,8 +556,9 @@ shadow_mesh = SubResource("ArrayMesh_he3sr")
[node name="WithHands" type="Node3D"]
script = ExtResource("1_h1xyo")
damage = 50
cooldown = 0.2
cooldown = 0.1
bullet_speed = 200
bullet_spread_script = ExtResource("2_4o3my")
[node name="Gun" parent="." instance=ExtResource("1_aaafm")]