Fixed linear holding of items, still working on rotation
This commit is contained in:
@@ -301,7 +301,7 @@ func _physics_process(delta):
|
||||
gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(level_control.current_gun_index + 1)
|
||||
else:
|
||||
held_item_rotation.y += deg_to_rad(45)
|
||||
held_item_rotation.y = clamp(held_item_rotation.y + deg_to_rad(45), deg_to_rad(0),deg_to_rad(360))
|
||||
|
||||
#Weapon Swap Down
|
||||
if Input.is_action_just_pressed("scroll_down") and !gun.anim_player.is_playing():
|
||||
@@ -310,7 +310,7 @@ func _physics_process(delta):
|
||||
gun.anim_player.play("swap_out")
|
||||
level_control.gun_spawn(level_control.current_gun_index - 1)
|
||||
else:
|
||||
held_item_rotation.y -= deg_to_rad(45)
|
||||
held_item_rotation.y = clamp(held_item_rotation.y - deg_to_rad(45), deg_to_rad(0),deg_to_rad(360))
|
||||
|
||||
# Weapon Swap by Numbers
|
||||
if Input.is_action_just_pressed("numb_1"):
|
||||
@@ -333,20 +333,6 @@ func _physics_process(delta):
|
||||
weapon_select(8)
|
||||
if Input.is_action_just_pressed("numb_0"):
|
||||
weapon_select(9)
|
||||
|
||||
# Move Held Items
|
||||
if held_item != null:
|
||||
var held_force_dir = moveable_holder.global_position - held_item.global_position
|
||||
held_item.set_constant_force(held_force_dir * 30)
|
||||
held_item.rotation = held_item_rotation #lerp(held_item.rotation, held_item_rotation, delta * 30)
|
||||
|
||||
#break when moved too far away
|
||||
var distance_from_player = abs(self.global_position - held_item.global_position)
|
||||
if distance_from_player.length() > 5:
|
||||
release_moveable()
|
||||
if stand_check.is_colliding():
|
||||
if stand_check.get_collider() == held_item:
|
||||
release_moveable()
|
||||
|
||||
#interact button
|
||||
if Input.is_action_just_pressed("interact"):
|
||||
@@ -376,6 +362,7 @@ func _physics_process(delta):
|
||||
if level_control.health <= 0:
|
||||
level_control.die()
|
||||
|
||||
hold_item()
|
||||
move_and_slide()
|
||||
weapon_tilt(input_dir.x, delta)
|
||||
weapon_sway(delta)
|
||||
@@ -459,18 +446,33 @@ func grab_moveable(body):
|
||||
held_item_gravity_cache = body.gravity_scale
|
||||
held_item_mass_cache = body.mass
|
||||
#change rigidbody settings
|
||||
body.linear_damp = 5
|
||||
body.angular_damp = 5
|
||||
body.linear_damp = 0 #5
|
||||
body.angular_damp = 0 #5
|
||||
body.mass = 1
|
||||
held_item.gravity_scale = 0
|
||||
|
||||
|
||||
func hold_item():
|
||||
# Move Held Items
|
||||
if held_item != null:
|
||||
var held_dir = moveable_holder.global_position - held_item.global_position
|
||||
var held_av = held_item_rotation - held_item.rotation
|
||||
held_item.linear_velocity = held_dir * 30
|
||||
held_item.angular_velocity = held_av * 10
|
||||
|
||||
#break when moved too far away
|
||||
var distance_from_player = abs(self.global_position - held_item.global_position)
|
||||
if distance_from_player.length() > 5:
|
||||
release_moveable()
|
||||
if stand_check.is_colliding():
|
||||
if stand_check.get_collider() == held_item:
|
||||
release_moveable()
|
||||
|
||||
func release_moveable():
|
||||
held_item_rotation = Vector3(0,0,0)
|
||||
held_item.gravity_scale = held_item_gravity_cache
|
||||
held_item.linear_damp = held_item_linear_damp_cache
|
||||
held_item.angular_damp = held_item_angular_damp_cache
|
||||
held_item.mass = held_item_mass_cache
|
||||
held_item.set_constant_force(Vector3(0,0,0))
|
||||
held_item = null
|
||||
|
||||
func hit(damage, fired_by, target_type):
|
||||
|
||||
Reference in New Issue
Block a user