-
Notifications
You must be signed in to change notification settings - Fork 11
/
player.gd
38 lines (33 loc) · 1.2 KB
/
player.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
extends KinematicBody
const MAXSPEED = 30
const ACCELERATION = 0.75
var inputVector = Vector3()
var velo = Vector3()
var cooldown = 0
const COOLDOWN = 8
onready var guns = [$Gun0, $Gun1]
onready var main = get_tree().current_scene
var Bullet = load("res://Bullet.tscn")
func _physics_process(delta):
inputVector.x = Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left")
inputVector.y = Input.get_action_strength("ui_up") - Input.get_action_strength("ui_down")
inputVector = inputVector.normalized()
velo.x = move_toward(velo.x, inputVector.x * MAXSPEED, ACCELERATION)
velo.y = move_toward(velo.y, inputVector.y * MAXSPEED, ACCELERATION)
rotation_degrees.z = velo.x * -2
rotation_degrees.x = velo.y / 2
rotation_degrees.y = -velo.x / 2
move_and_slide(velo)
transform.origin.x = clamp(transform.origin.x, -15, 15)
transform.origin.y = clamp(transform.origin.y, -10, 10)
#shooting
if Input.is_action_pressed("ui_accept") and cooldown <= 0:
cooldown = COOLDOWN * delta
for i in guns:
var bullet = Bullet.instance()
main.add_child(bullet)
bullet.transform = i.global_transform
bullet.velo = bullet.transform.basis.z * -600
#cooldown
if cooldown > 0:
cooldown -= delta