Seems more reliable than the original method but not perfect
This commit is contained in:
@@ -38,15 +38,19 @@ func _physics_process(delta):
|
||||
func _on_body_entered(body: Node) -> void:
|
||||
|
||||
if !body.is_in_group("player"):
|
||||
print("BODY HIT - " + str(body))
|
||||
#Break Breakable Objects
|
||||
if body.is_in_group("breakable"):
|
||||
body.breaking(linear_velocity)
|
||||
|
||||
if body.is_in_group("switch"):
|
||||
body.hit()
|
||||
|
||||
|
||||
if ray.is_colliding():
|
||||
print("ray collision")
|
||||
else:
|
||||
print("no ray collision")
|
||||
|
||||
mesh.visible = false
|
||||
|
||||
if 1>2:#ray.is_colliding() and !ray.get_collider().is_in_group("player"):
|
||||
if ray.is_colliding() and !ray.get_collider().is_in_group("player"):
|
||||
#Bullet Hole Effect
|
||||
ray.get_collider().add_child(instance_bullethole)
|
||||
instance_bullethole.global_transform.origin = ray.get_collision_point()
|
||||
@@ -55,19 +59,13 @@ func _on_body_entered(body: Node) -> void:
|
||||
else:
|
||||
instance_bullethole.look_at(ray.get_collision_point() + ray.get_collision_normal())
|
||||
|
||||
#Break Breakable Objects
|
||||
if ray.get_collider().is_in_group("breakable"):
|
||||
var current_velocity = transform.basis * Vector3(0,0,-1 * bullet_force_mod)
|
||||
ray.get_collider().breaking(current_velocity)
|
||||
|
||||
#Hit Enemies
|
||||
if ray.get_collider().is_in_group("enemy_target"):
|
||||
hit_indicator.play()
|
||||
enemy_particles.emitting = true
|
||||
ray.get_collider().hit(bullet_damage)
|
||||
|
||||
|
||||
#Switch Switches
|
||||
if ray.get_collider().is_in_group("switch"):
|
||||
ray.get_collider().hit()
|
||||
|
||||
queue_free()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
extends Node3D
|
||||
|
||||
const recoil_amount : Vector3 = Vector3(.5,.1,.1)
|
||||
|
||||
var bullet_speed
|
||||
var bullet_drop
|
||||
var random_spread_amt
|
||||
@@ -42,7 +44,10 @@ func _process(delta):
|
||||
if ray.is_colliding() and ray.get_collider() != null:
|
||||
if ray.get_collider().is_in_group("player"):
|
||||
var player = ray.get_collider()
|
||||
var snap_amount = 10
|
||||
var speed_amount = 10
|
||||
player.level_control.health -= bullet_damage
|
||||
player.recoil.add_recoil(recoil_amount,snap_amount,speed_amount)
|
||||
|
||||
if player.level_control.health <= bullet_damage:
|
||||
player.level_control.last_hit = fired_by
|
||||
|
||||
@@ -111,7 +111,7 @@ func shoot(delta):
|
||||
instance_casing.position = casing_ejector.global_position
|
||||
instance_casing.transform.basis = casing_ejector.global_transform.basis
|
||||
get_tree().get_root().add_child(instance_casing)
|
||||
player.recoil.add_recoil(recoil_amount)
|
||||
player.recoil.add_recoil(recoil_amount,10,10)
|
||||
if fire_mode != 0:
|
||||
cycle_count -= 1
|
||||
|
||||
|
||||
@@ -210,10 +210,11 @@ func _physics_process(delta):
|
||||
|
||||
#Land Sound
|
||||
if velocity.y < .1 and self.is_on_floor() and moving_fast == true:
|
||||
print("LAND SOUND")
|
||||
var land_volume = clamp( moving_fast_top_speed - 20 ,-10,0)
|
||||
var recoil_amount = Vector3(-.1,0,0)
|
||||
land_sound.volume_db = land_volume
|
||||
land_sound.play()
|
||||
recoil.add_recoil(recoil_amount,10,2)
|
||||
moving_fast_top_speed = 0.0
|
||||
moving_fast = false
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
extends Node3D
|
||||
|
||||
var recoil_amount : Vector3 = Vector3(.1,0,0)
|
||||
var snap_amount : float = 10
|
||||
var speed : float = 4
|
||||
var speed : float = 10
|
||||
var current_rotation : Vector3
|
||||
var target_rotation : Vector3
|
||||
|
||||
@@ -17,7 +16,9 @@ func _process(delta: float) -> void:
|
||||
current_rotation = lerp(current_rotation, target_rotation, snap_amount * delta)
|
||||
basis = Quaternion.from_euler(current_rotation)
|
||||
|
||||
func add_recoil(recoil_amount) -> void:
|
||||
func add_recoil(recoil_amount,snap_change,speed_change) -> void:
|
||||
snap_amount = snap_change
|
||||
speed = speed_change
|
||||
var recoil_x = recoil_amount.x
|
||||
var recoil_y = randf_range(-recoil_amount.y,recoil_amount.y)
|
||||
var recoil_z = randf_range(-recoil_amount.z,recoil_amount.z)
|
||||
|
||||
@@ -156,7 +156,7 @@ func fire(delta):
|
||||
instance_bullet.player_velocity = player.velocity
|
||||
instance_bullet.instance_bullethole = bullethole.instantiate()
|
||||
get_tree().get_root().add_child(instance_bullet)
|
||||
player.recoil.add_recoil(recoil_amount)
|
||||
player.recoil.add_recoil(recoil_amount,10,10)
|
||||
chamber.rotate_object_local(Vector3(0,-1,0),deg_to_rad(60))
|
||||
|
||||
func reload(delta):
|
||||
|
||||
@@ -100,7 +100,7 @@ func shoot(delta):
|
||||
instance_bullet.blast_power = blast_power
|
||||
instance_bullet.player_position = player.global_position
|
||||
get_tree().get_root().add_child(instance_bullet)
|
||||
player.recoil.add_recoil(recoil_amount)
|
||||
player.recoil.add_recoil(recoil_amount,10,10)
|
||||
if fire_mode != 0:
|
||||
cycle_count -= 1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user