Hi, I'm a total noob and just starting out trying to put a small game together and 'learning (the hard way) by doing'.
But alas I've hit a snag - the bullets fly down instead of outwards from the muzzle (they fire from the right place but the direction is wrong).
I have a player scene (consisting of a RigidBody2D with a Position2d as Muzzle) and a bullet scene. From the player controls it looks like this
Player script:
if Input.is_action_pressed("ui_fireone"):
$Muzzle.shoot()
Muzzle script:
extends Position2D
const Bullet = preload("res://Bullet.tscn")
onready var sound_shoot = $Shoot
func shoot ():
var bullet = Bullet.instance()
bullet.global_position = global_position
bullet.set_as_toplevel(true)
add_child(bullet)
sound_shoot.play()
return true
Bullet script:
extends KinematicBody2D
export var speed = 500
func _physics_process(delta):
var velocity = Vector2 (0, speed).rotated (global_rotation)
global_position += velocity * delta
I'm guessing that 'speed' in the bullet script is what's wrong, but I'm without a clue to solve it...
Any help appreciated - exact instructions even more so :)
Thanks!