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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
extends RigidBody
class_name NetMachine
var in_use: bool = false
var controllable: bool = false
var user: NetChar = null
var world: Spatial = null
func _ready():
world = get_tree().get_root().find_node("GAMEWORLD", true, false)
remote func update_phys_transform(t: Transform, lv: Vector3, av: Vector3):
transform = t
linear_velocity = lv
angular_velocity = av
remotesync func net_apply_impulse(impulse_v: Vector3):
apply_central_impulse(impulse_v)
func _integrate_forces(_state: PhysicsDirectBodyState):
if is_network_master() and mode == MODE_RIGID:
rpc_unreliable("update_phys_transform", transform, linear_velocity, angular_velocity)
remotesync func set_net_owner(id: int, char_name: String):
set_network_master(id)
if id == 1 and char_name == "NONE": #not under control
on_no_control()
if user != null:
user.lose_machine()
user = null
in_use = false
else:
in_use = true
user = world.get_node("PLAYERS/"+char_name)
user.take_control_of_machine(self)
if is_network_master():
on_new_control()
func relinquish_control():
rpc("set_net_owner", 1, "NONE")
#TO BE OVERRIDDEN BY CHILDREN
func on_new_control():
pass
func on_no_control():
pass
func attack1():
pass
func attack2():
pass
func direction_input(_fwd: float,_bwd: float,_left: float,_right: float,_left2: float,_right2: float):
pass
func misc_input(_ctrl: float,_space: float,_shift: float):
pass
func mouse_input(_m1: float,_m3: float,_m2: float): #used for long-press actions
pass
|