I'm new to godot and I was trying to make a asteriods type game. But i'm having trouble getting my space ship to shoot.
The issue is that I can't get the bullet to fire in direction of the ship. I set an 'angle' variable in the ship and assign it to the bullet once it has been instanced, but i'm not sure how to use it in the bullet. The bullet will just move right no matter the angle of the ship.
Ship Firing Code:
func _process(_delta):
if Input.is_action_just_pressed("action_fire"):
var Bullet_Instance = Bullet.instance()
Bullet_Instance.angle = angle
owner.add_child(Bullet_Instance)
Bullet Code:
extends KinematicBody2D
var angle = 0
var direction = Vector2(cos(angle), sin(angle))
func _physics_process(_delta):
move_and_slide(direction*500)
I'm pretty sure that the angle variable is being reset to 0 in the bullet code after it has been set in the ship code, but i'm not sure how to fix this. Thanks.