Bullets follow mouse after being shot

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

Hello everyone. I am a begginer in Godot and GDScript, so my question might have an obvious answer.

I am making a turret game but when the player shoots, the bullets follow the mouse.

Here is the code for bullet movement and spawning:

if Input.is_action_pressed("shoot_bullet") and can_fire:
	var bullet = bullet_scene.instance();
	bullet.position = $point.position;
	bullet.apply_impulse(Vector2(), Vector2(bullet_speed, 0).rotated(deg2rad(rotation_degrees - 90)));
	print("Shooted a bullet");
	can_fire = false;
	$Timer.start(fire_rate); yield($Timer, "timeout") 
	can_fire = true;

What is that I have implemented wrong? How can I stop this? Thanks in advance

I don’t see any input from the mouse in your code.

toxicvgl | 2022-10-25 10:44

It is the “shoot_bullet” action. I have registered it as left click

PT | 2022-10-25 12:05

Does bullet have a script?

Clamydeef | 2022-10-27 07:12

None else that affects movement

PT | 2022-10-28 15:50

Can you provide more context? What is the nodes hierarchy? It would be nice to have the full code or at least what is relevant, not just a bit of code that won’t work by itself so I can test it and see what it does. I would also recommend to use the Timout signal of your timer node instead of yielding, I think it won’t work properly…? Not sure, I am still relatively new too.

nanto2016 | 2023-05-22 20:00