pellet spread, bulletholes and balance fixes
This commit is contained in:
parent
eabc137ce8
commit
74e37f8a18
17 changed files with 261 additions and 72 deletions
|
|
@ -1,5 +1,7 @@
|
|||
extends Node
|
||||
|
||||
const BULLET_HOLE: PackedScene = preload("uid://u8aj6fs32ql6")
|
||||
|
||||
enum TEAMS {
|
||||
DEFENCE,
|
||||
ATTACK,
|
||||
|
|
@ -325,56 +327,8 @@ func shoot(id:int , limb_damage: int, torso_damage: int,head_damage: int, distan
|
|||
var collision = space.intersect_ray(ray)
|
||||
|
||||
|
||||
if collision != {} and collision["collider"] is Player:
|
||||
var hit_player: Player = collision["collider"]
|
||||
var shape_object: CollisionShape3D = hit_player.shape_owner_get_owner(collision["shape"])
|
||||
var reduction: float = 1
|
||||
var damage: int = 0
|
||||
|
||||
match shape_object.get_groups()[0]:
|
||||
"Head":
|
||||
damage = head_damage
|
||||
"Limb":
|
||||
damage = limb_damage
|
||||
_:
|
||||
damage = torso_damage
|
||||
|
||||
if damage_reduction_curve != null:
|
||||
var distance_to_hit = (player_camera.global_position - collision["position"]).length()/distance
|
||||
reduction = damage_reduction_curve.sample(distance_to_hit)
|
||||
|
||||
hit_player.take_damage(int(float(damage) * reduction))
|
||||
|
||||
|
||||
func shoot_pellets(id:int,amount: int, limb_total_damage: int, torso_total_damage: int,head_total_damage: int, distance: float, arc: float, damage_reduction_curve: Curve = null):
|
||||
if multiplayer.is_server() == false:
|
||||
return
|
||||
|
||||
var player: Player = player_nodes[id]
|
||||
var player_camera: Camera3D = player.get_node("Camera3D")
|
||||
var space: PhysicsDirectSpaceState3D = player.get_world_3d().direct_space_state
|
||||
var head_damage: int = head_total_damage / amount
|
||||
var torso_damage: int = torso_total_damage / amount
|
||||
var limb_damage: int = limb_total_damage / amount
|
||||
|
||||
for i in range(amount):
|
||||
var endpoint: Vector3 = player_camera.global_position - player_camera.global_basis.z.rotated(Vector3.RIGHT,randf_range(-arc/2,arc/2)).rotated(Vector3.UP,randf_range(-arc/2,arc/2)) * distance
|
||||
|
||||
var ray = PhysicsRayQueryParameters3D.create(player_camera.global_position,endpoint,1)
|
||||
ray.exclude = [player.get_rid()]
|
||||
ray.collide_with_areas = false
|
||||
match player.team:
|
||||
TEAMS.DEFENCE:
|
||||
ray.collision_mask |= ATTACK_LAYER
|
||||
TEAMS.ATTACK:
|
||||
ray.collision_mask |= DEFENCE_LAYER
|
||||
_:
|
||||
ray.collision_mask |= ATTACK_LAYER | DEFENCE_LAYER
|
||||
|
||||
var collision = space.intersect_ray(ray)
|
||||
|
||||
|
||||
if collision != {} and collision["collider"] is Player:
|
||||
if collision != {}:
|
||||
if collision["collider"] is Player:
|
||||
var hit_player: Player = collision["collider"]
|
||||
var shape_object: CollisionShape3D = hit_player.shape_owner_get_owner(collision["shape"])
|
||||
var reduction: float = 1
|
||||
|
|
@ -393,6 +347,71 @@ func shoot_pellets(id:int,amount: int, limb_total_damage: int, torso_total_damag
|
|||
reduction = damage_reduction_curve.sample(distance_to_hit)
|
||||
|
||||
hit_player.take_damage(int(float(damage) * reduction))
|
||||
|
||||
var bullet_hole: Decal = BULLET_HOLE.instantiate()
|
||||
dynamic_objects_parent.add_child(bullet_hole,true)
|
||||
|
||||
var rotation_quat: Quaternion = Quaternion(Vector3.UP,collision["normal"])
|
||||
bullet_hole.quaternion *= rotation_quat
|
||||
bullet_hole.global_position = collision["position"]
|
||||
|
||||
|
||||
|
||||
func shoot_pellets(id:int,limb_pellet_damage: int, torso_pellet_damage: int,head_pellet_damage: int, distance: float, pellets: PackedVector2Array, damage_reduction_curve: Curve = null):
|
||||
if multiplayer.is_server() == false:
|
||||
return
|
||||
|
||||
var amount: int = len(pellets)
|
||||
|
||||
var player: Player = player_nodes[id]
|
||||
var player_camera: Camera3D = player.get_node("Camera3D")
|
||||
var space: PhysicsDirectSpaceState3D = player.get_world_3d().direct_space_state
|
||||
|
||||
for i in range(amount):
|
||||
var endpoint: Vector3 = player_camera.project_position(pellets[i],distance)
|
||||
|
||||
var ray = PhysicsRayQueryParameters3D.create(player_camera.global_position,endpoint,1)
|
||||
ray.exclude = [player.get_rid()]
|
||||
ray.collide_with_areas = false
|
||||
match player.team:
|
||||
TEAMS.DEFENCE:
|
||||
ray.collision_mask |= ATTACK_LAYER
|
||||
TEAMS.ATTACK:
|
||||
ray.collision_mask |= DEFENCE_LAYER
|
||||
_:
|
||||
ray.collision_mask |= ATTACK_LAYER | DEFENCE_LAYER
|
||||
|
||||
var collision = space.intersect_ray(ray)
|
||||
|
||||
|
||||
if collision != {}:
|
||||
if collision["collider"] is Player:
|
||||
var hit_player: Player = collision["collider"]
|
||||
var shape_object: CollisionShape3D = hit_player.shape_owner_get_owner(collision["shape"])
|
||||
var reduction: float = 1
|
||||
var damage: int = 0
|
||||
|
||||
match shape_object.get_groups()[0]:
|
||||
"Head":
|
||||
damage = head_pellet_damage
|
||||
"Limb":
|
||||
damage = limb_pellet_damage
|
||||
_:
|
||||
damage = torso_pellet_damage
|
||||
|
||||
if damage_reduction_curve != null:
|
||||
var distance_to_hit = (player_camera.global_position - collision["position"]).length()/distance
|
||||
reduction = damage_reduction_curve.sample(distance_to_hit)
|
||||
|
||||
hit_player.take_damage(int(float(damage) * reduction))
|
||||
|
||||
var bullet_hole: Decal = BULLET_HOLE.instantiate()
|
||||
dynamic_objects_parent.add_child(bullet_hole,true)
|
||||
|
||||
var rotation_quat: Quaternion = Quaternion(Vector3.UP,collision["normal"])
|
||||
|
||||
bullet_hole.quaternion *= rotation_quat
|
||||
bullet_hole.global_position = collision["position"]
|
||||
|
||||
func interact(id: int) -> void:
|
||||
if multiplayer.is_server() == false:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue