HI, ok basically i'm trying to make a gun in godot and it's not working out too well the bullets are flying everywhere not following the mouse at all except when the player isn't moving even then they're too slow and sometimes it goes the complete opposite way
i used an instance of a scene for the bullet here's my code:
func createBulletInstance() -> void:
if timeBetweenShots <= 0 && not global.first_bullet:
var b = bullet.instance()
add_child(b)
b.start(global.bullet_spawn_pos, global.dif_bullet_mouse)
timeBetweenShots = maxTimeBetweenShots
else:
timeBetweenShots -= get_process_delta_time()
that's in the main scene script and here's the bullet script:
extends Area2D
export (int) var speed
export (int) var damage
var velocity = Vector2()
var difBulletMouse: Vector2
func start(_positon, _direction):
position = _positon
rotation_degrees = global.gun_rotation
velocity = _direction * speed
print(_direction, speed)
func _process(delta: float) -> void:
# print(velocity, delta)
global.dif_bullet_mouse = calculateGlobalDifBulletMouse()
position += velocity * delta
func calculateGlobalDifBulletMouse() -> Vector2:
difBulletMouse = get_global_mouse_position() - global_position
return difBulletMouse
here's an example of what the console prints ( _direction, speed):
i tried shooting at exactly the same place over and over
(1064.097046, -28.269012)2
(504.196075, 121.085732)2
(-1106.026978, -303.778748)2
(2494.589355, 624.708252)2
(313.460938, 33.704681)2
(-834.855591, -42.236572)2
here's the print for (velocity, delta):
(0, 0)0.016667
(0, 0)0.016667
(0, 0)0.016667
this is where i shoot
(1548.19397, 239.461975)0.016667
(0, 0)0.016667
(1548.19397, 239.461975)0.016667
(0, 0)0.016667
(1548.19397, 239.461975)0.016667
(0, 0)0.016667
(1548.19397, 239.461975)0.016667
(0, 0)0.016667
loops forever
Thanks for trying to help!!!!!!!