Godot Version
4.4.1
Question
Hello! This is my first 3D game ever, I started using godot early last month after using gamemaker studio 2 for nearly 6 years.
heres a video of my game and the issues im having.
Regarding progress bars, I’ve been working on the basics for this game for a couple weeks and I’m now adding multiplayer functionality. It was going well, but I’ve run into this bug and I’m stumped. Genuinely do not know what’s causing it. The player has 4 ammo counting progress bars on the screen that seem to lock on their default values any time a new player joins, but the newly joined players HUD works fine. The player still consumes ammo, runs out and needs to reload, however it’s not at all reflected by their HUD. I have no idea why this happens. The HUD isn’t connected to a multiplayer synchroniser or anything, it’s really grinding my gears. I’ve also confirmed that the code does run by just putting print() in the functions one by one. to my knowledge, there’s no reason this shouldn’t work.
Here’s the code:
#'gun' objects _process() function, tells the player to update the bars
func _process(delta):
##set HUD icons and values
if player:
player._update_ammo_counters(hand_side, float(p_ammo), p_ammo_max, float(s_ammo), s_ammo_max)
_set_icon_textures(p_ability, s_ability)
#player updating ammo bars
func _update_ammo_counters(hand_side, val_p, max_p, val_s, max_s):
if hand_side == "LEFT":
$Control/CanvasLayer/LeftBar1.set_value(val_p)
$Control/CanvasLayer/LeftBar1.max_value = max_p
$Control/CanvasLayer/LeftBar2.set_value(val_s)
$Control/CanvasLayer/LeftBar2.max_value = max_s
if hand_side == "RIGHT":
$Control/CanvasLayer/RightBar1.set_value(val_p)
$Control/CanvasLayer/RightBar1.max_value = max_p
$Control/CanvasLayer/RightBar2.set_value(val_s)
$Control/CanvasLayer/RightBar2.max_value = max_s
#hands 'set icon textures' function
func _set_icon_textures(primary, secondary):
if p_icon:
p_icon.texture = load(icons[primary])
if s_icon:
s_icon.texture = load(icons[secondary])
Now the bullet issue, as you can see they act quite weird. I think I’ve seen issues similar to this before, my theory is that the bullet is always updating its direction to be pointing at wherever the raycast lands, rather than just setting its direction when its spawned and leaving it there, but nothing I’ve tried seems to get rid of this behavior, everything just makes it less or more frequent.
heres the code in the bullets:
#this is the event used to spawn bullets.
@rpc("authority", "call_remote", "reliable")
func _projectile_shoot(prj_spd, prj_acc, prj_grv, dmg, consumes_ammo, POrS):
_play_sound(POrS, _POrS(POrS, pors_variables.TriggerSound))
var instance
instance = _POrS(POrS, pors_variables.ProjectileScene).instantiate()
instance.position = barrel.global_position
instance.transform.basis = barrel.global_transform.basis
var centered_dir = _get_center_coords()
instance._set_variables(prj_spd, prj_grv, prj_acc, dmg, centered_dir)
get_tree().get_root().add_child(instance)
#bullet process function
func _process(delta):
if center_dir != null:
position += global_position.direction_to(center_dir) * speed * delta
else:
position += transform.basis.z * speed * delta
if ray.is_colliding() and ray.get_collider():
if ray.get_collider().is_in_group("Living") and !hit:
ray.get_collider()._take_damage(damage)
hit = true
mesh.visible = false
particle.emitting = true
await get_tree().create_timer(1.0).timeout
queue_free()
func _get_center_coords(): #gets the coordinates at the center of the screen based on the player raycast
if hitscan_ray.is_colliding():
return hitscan_ray.get_collision_point()
else:
return null