-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGreenTank.gd
38 lines (25 loc) · 846 Bytes
/
GreenTank.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 KinematicBody2D
# Max speeds
const FWD_SPEED = 40
const TURN_SPEED = 90 # degrees per second
# Global Vars
var velocity = Vector2.ZERO
var heading
func _ready():
heading = get_rotation_degrees()
print("heading: ", heading)
func _physics_process(delta):
var turn = TURN_SPEED * (Input.get_action_strength("ui_right") - Input.get_action_strength("ui_left"))
heading = heading + (turn * delta)
if turn != 0:
set_rotation_degrees(heading)
print("heading: ", heading)
var fwd = FWD_SPEED * delta * (Input.get_action_strength("ui_down") - Input.get_action_strength("ui_up"))
if fwd !=0:
var adj_heading = heading+90
velocity.x = fwd * cos(adj_heading * (PI/180))
velocity.y = fwd * sin(adj_heading * (PI/180))
print("velocity: ", velocity)
else:
velocity = Vector2.ZERO
move_and_collide(velocity)