extends KinematicBody2D var bullet = load("res://Bullet.tscn") var player_movement_speed = 256 # pixels per second var velocity = Vector2(0, 0) var pointer var velocity_mul = 1 func _ready(): # Called every time the node is added to the scene. pointer = get_node("Pointer") set_fixed_process(true) func _fixed_process(delta): var point_dir = (get_viewport().get_mouse_pos() - get_global_pos()).normalized() if Input.is_action_pressed("move_left"): velocity.x = -1 if Input.is_action_pressed("move_right"): velocity.x = 1 if Input.is_action_pressed("move_up"): velocity.y = -1 if Input.is_action_pressed("move_down"): velocity.y = 1 if Input.is_action_pressed("move_slow"): velocity_mul = 0.5 else: velocity_mul = 1 # shooty if Input.is_action_pressed("attack_primary"): var new_bullet = bullet.instance() new_bullet.set_pos(pointer.get_node("Sprite").get_global_pos() + velocity) new_bullet.set_bullet_velocity(velocity, point_dir) get_parent().add_child(new_bullet) # add to tree # melee actually? if Input.is_action_pressed("attack_secondary"): pass # tell child node to point at given mouse position (in screenspace) pointer.look_at(get_viewport().get_mouse_pos()) self.move(velocity * velocity_mul * (player_movement_speed * delta)) velocity.x = 0 velocity.y = 0