Does exporting variables change object behavior?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ImperialPhoenix

So, i am making this 2d platformer shooting game. I created a bullet and have a local speed variable. It was working fine. Now, i need to change the speed of the bullet and exported the variable “speed” and now the bullet passes through the player. Is there anything i can do? The bullet is Area2D and Player is KinematicBody2D.

#Shooting

func shoot():
var b = Bullet.instance()
owner.add_child(b)
b.transform = $Pivot/Position2D.global_transform
current_ammo -= 1
if current_ammo == 0:
$AmmoTimer.start()
$ReloadTimer.start()
#if current_gun == “AR”:
#b.speed = 3000
#elif current_gun == “Pistol”:
#b.speed = 1500

func _input(event):
if event.is_action_pressed(“Player2 Shoot”) and $ReloadTimer.is_stopped() and $AmmoTimer.is_stopped():
shoot()

func _on_Test_AR_Get_Player2():
$ReloadTimer.wait_time = 0.01
$AmmoTimer.wait_time = 10
total_ammo = 30
current_ammo = total_ammo
current_gun = “AR”

func _on_AmmoTimer_timeout():
current_ammo = total_ammo

func _process(delta):
$Label.text = str(current_ammo)
$HealthBar.value = health_points
if health_points == 0:
hide()
set_process(false)
set_process_input(false)
set_collision_layer(false)
set_collision_mask(false)

#Bullet

export(int) var speed = 1500
export(int)var damage = 10

func _physics_process(delta):
position += transform.x * speed * delta

func _on_Bullet_body_entered(body):
if body.is_in_group(“Player2”):
body.health_points -= damage
queue_free()

when you say the bullet pass through, does it mean that _on_bullet_body_entered(body) is not called?
try adding some print(“test”) around the code to check on which point the code stop working as you expect

Andrea | 2021-08-28 10:44

Okay, i will do that. Sorry for the late reply, was having some heavy work…

Update: Yes, it is not being called.

ImperialPhoenix | 2021-09-06 07:14

Did you actually only added export (int) and it stopped working?
Does it work if you change it to float?
Does it work with a smaller value? E.g. 100

Andrea | 2021-09-06 07:48

Actually, I noticed and removing the export(int) doesn’t change anything anymore.

I tried the methods given above, but unfortunately none of them work.

ImperialPhoenix | 2021-09-07 16:06

Actually, I noticed and removing the export(int) doesn’t change anything anymore.

I tried the methods given above, but unfortunately none of them work.

edit: I will just use raycast, i just saw KidsCanCode’s video and understood what was wrong, so yeah. Thanks for helping too! :slight_smile:

ImperialPhoenix | 2021-09-07 16:17