bullet not moving

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: 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!!

:bust_in_silhouette: Reply From: kris_bsx

Hi,
I am sorry i don’t know what is wrong with your code.

I tried this code and does not have any problem (the sprite is moving):

extends Area2D

var velocity = Vector2()

func start():
    position = Vector2(10, 10)
    velocity = Vector2(1, 1) * 10

func _process(delta: float) -> void:
    position += velocity * delta;

The objects used for my test:

Area2D
- CollisionPolygon2D
    - Sprite

I don’t know what is wrong in your game:
Maybe you forgot to set the speed to a value greater than 0, or maybe your object is colliding with another and that keeps him from moving.

I’m not very experienced with Godot so I don’t know what to say more.

i tried adding a collision shape to my bullet but that didn’t work
still thanks for your help

ROBOTOO007 | 2020-04-29 18:05

:bust_in_silhouette: Reply From: ROBOTOO007

Ok 1 day later I found the problem it was having the speed set to 0 on the bullet scene

Sorry I hadn’t seen your message before. I said in my message that you may have forgotten to set a speed greater than zero . You haven’t read my answer entirely .
That’s good if you did solve your problem.

kris_bsx | 2020-05-13 09:33