Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | TheMoose |
extends KinematicBody2D
export (int) var speed = 200
var velocity = Vector2()
var Bullet = load("res://Bullet.tscn")
var shoot_timer = 0
func get_input():
velocity = Vector2()
if Input.is_action_pressed('ui_right'):
velocity.x += 1
if Input.is_action_pressed('ui_left'):
velocity.x -= 1
if Input.is_action_pressed('ui_down'):
velocity.y += 1
if Input.is_action_pressed('ui_up'):
velocity.y -= 2
velocity = velocity * speed
func shoot():
if Input.is_action_just_pressed("ui_accept") & shoot_timer == 0:
var bullet = Bullet.instance()
get_parent().add_child(bullet)
bullet.position = Vector2($".".position.x, $".".position.y - 40)
shoot_timer = 50
func _physics_process(delta):
get_input()
shoot()
move_and_slide(velocity)
shoot_timer = shoot_timer - 1
FYI, when editing your post, there is a button that looks like this: {}
This button will format your code so that it is readable.
kidscancode | 2018-06-06 16:24