Advertisement
Eynopinate69

Untitled

Jan 28th, 2024
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 0.70 KB | Gaming | 0 0
  1. extends CharacterBody2D
  2.  
  3. @export var SPEED = 300
  4.  
  5. var ammo = 0
  6.  
  7. func _physics_process(_delta):
  8.     aiming()
  9.     shooting()
  10.     var direction = Input.get_vector("left","right","up","down")
  11.     velocity = direction * SPEED
  12.     move_and_slide()
  13. func aiming():
  14.     var aim
  15.     aim = get_global_mouse_position()
  16.     look_at(aim)
  17. func shoot():
  18.     const BULLET = preload("res://scene/bullets.tscn")
  19.     var new_bullets = BULLET.instantiate()
  20.     #spawn bullets at point
  21.     new_bullets.global_position = %bullet_spawn.global_position
  22.     #rotation of the bullet
  23.     new_bullets.global_rotation = %bullet_spawn.global_rotation
  24.     %bullet_spawn.add_child(new_bullets)
  25. func shooting():
  26.     if Input.is_action_just_pressed("shoot"):
  27.         shoot()
  28.        
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement