Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extends KinematicBody2D
- var speed = 160
- var bullet = preload("res://Bullet.tscn")
- var can_fire = true
- var shooting = false
- var rate_of_fire = 0.08
- var move_target = Vector2(-670,-647)
- var shoot_target = Vector2()
- var velocity = Vector2()
- func _input(event):
- if Input.is_action_pressed("move_to"):
- move_target = get_global_mouse_position()
- look_at(move_target)
- if Input.is_action_pressed("fire"):
- shoot_target = get_global_mouse_position()
- func _physics_process(delta):
- MoveLoop()
- ShootLoop()
- func MoveLoop():
- velocity = position.direction_to(move_target) * speed
- if position.distance_to(move_target) > 1:
- velocity = move_and_slide(velocity)
- func ShootLoop():
- if Input.is_action_pressed("fire") and can_fire == true:
- can_fire = false
- shooting = true
- speed = 75
- look_at(shoot_target)
- get_node("playerTurnAxis").rotation = get_angle_to(get_global_mouse_position())
- var bullet_instance = bullet.instance()
- bullet_instance.position = get_node("playerTurnAxis/bulletSpawnPoint").get_global_position()
- bullet_instance.look_at(get_global_mouse_position())
- get_parent().add_child(bullet_instance)
- yield(get_tree().create_timer(rate_of_fire), "timeout")
- can_fire = true
- shooting = false
- speed = 160
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement