Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | ROBOTOO007 |
Hi i’m new to game developpement and am trying to make a gun,
it follows the mouse and it can spawn bullets using instances of this code but for some reason the bullets wont move, i’ve been trying to fix this issue for over 3hours please help
here’s my code:
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
func _process(delta: float) -> void:
print(position)
global.dif_bullet_mouse = calculateGlobalDifBulletMouse()
position += velocity * delta
func calculateGlobalDifBulletMouse() -> Vector2:
difBulletMouse = get_global_mouse_position() - global_position
return difBulletMouse
ps: the speed is set to 200 so that shouldn’t be a problem
and here’s the code for the _direction:
func createBulletInstance() -> void:
if timeBetweenShots <= 0 && not global.first_bullet:
var b = bullet.instance()
var dir = Vector2(1, 0).rotated($gun/gun.global_rotation)
add_child(b)
b.start(global.bullet_spawn_pos, dir)
timeBetweenShots = maxTimeBetweenShots
else:
timeBetweenShots -= get_process_delta_time()
Thanks for checkign this out!!