bullets wont work correctly

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

basically im trying to make a basic gun in my game but the bullets wont spawn at the right place and they arent rotated correctly and they dont go in the right direction
here’s my bullet code:

export (int) var speed
var velocity = Vector2()
var difBulletMouse: Vector2

func start(_positon, _direction, _rotation):
	$bullet.scale = Vector2(10,10)
	position = _positon
	velocity = _direction * speed
	rotation_degrees = _rotation

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

and here’s my player code:

there's more code here but it's irrelevant
	if Input.is_action_just_pressed("shoot"):
		shoot($player_arm/bullet_SpawnPoint.position, arm_direction.normalized(), $player_arm.rotation_degrees)

func shoot(_position, _direction, _rotation):
	var bullet_inst = bullet.instance()
	bullet_inst.start(_position, _direction, _rotation)
:bust_in_silhouette: Reply From: ambrosecollector

If I’m understanding correctly, the position variables you’re calling are relative to the nodes’ parents, and then you’re adding the bullet to the parent’s player (I’m guessing the scene). So for instance, if the position of the spawn point is (1, 4) relative to the player, it will spawn at (1, 4) relative to the scene instead. There are global_position, global_rotation_degrees, etc properties that you could be using, instead, and that may fix it.

This code doesn’t explain how the arm_direction variable is being generated, so it’s hard to say how that’s effecting the direction your bullet is travelling

Hope this helps, and if it does, and you let me know how arm_direction is being generated, I may be able to help with that, too!