extends KinematicBody2D
var speed = 500
var velocity = Vector2()
var bullet_speed = 2000
var bullet = preload("res://Bullet.tscn")
func getinput():
velocity = Vector2()
if Input.isactionpressed("right"):
velocity.x += 1
if Input.isactionpressed("left"):
velocity.x -= 1
if Input.isactionpressed("down"):
velocity.y += 1
if Input.isaction_pressed("up"):
velocity.y -= 1
velocity = velocity.normalized() * speed
look_at(get_global_mouse_position())
func physicsprocess(delta):
getinput()
velocity = moveand_slide(velocity)
if Input.is_action_pressed("LMB"):
fire()
func fire():
var bulletinstance = bullet.instance()
bulletinstance.position = getglobalmouseposition()
bulletinstance.rotatedegress = rotationdegrees
bulletinstance.applyimpulse(Vector2(),Vector2(bulletspeed,0).rotated(rotation))
gettree().getroot().calldeferred("addchild",bulletinstance)