Browse Source

npc rebirth

shuvit 5 years ago
parent
commit
603f4926e4
3 changed files with 104 additions and 80 deletions
  1. 3
    2
      scripts/aiRecord.py
  2. 21
    3
      scripts/ragdoll.py
  3. 80
    75
      scripts/walker_states.py

+ 3
- 2
scripts/aiRecord.py View File

16
 DAF = 0
16
 DAF = 0
17
 
17
 
18
 npc_index = own['npc_index']
18
 npc_index = own['npc_index']
19
-#print(dict['spawned_npc_decks'], npc_index, 'spawned deck list')
19
+print(dict['spawned_npc_decks'], npc_index, 'spawned deck list')
20
 deck = dict['spawned_npc_decks'][npc_index]
20
 deck = dict['spawned_npc_decks'][npc_index]
21
 trucks = dict['spawned_npc_trucks'][npc_index]
21
 trucks = dict['spawned_npc_trucks'][npc_index]
22
 #deck = scene.objects[deck]
22
 #deck = scene.objects[deck]
166
                 deck.worldPosition = position
166
                 deck.worldPosition = position
167
                 trucks.worldPosition = position                   
167
                 trucks.worldPosition = position                   
168
                 
168
                 
169
-        except:
169
+        except Exception as e:
170
+            print(e)
170
             print('npc positioning not working')
171
             print('npc positioning not working')
171
             #pass
172
             #pass
172
     #-----Orientation-----#
173
     #-----Orientation-----#

+ 21
- 3
scripts/ragdoll.py View File

190
             if dict['lUD'] < -.08:
190
             if dict['lUD'] < -.08:
191
                 physBody = own['rd_rb']
191
                 physBody = own['rd_rb']
192
                 excludes = ['npc_ed_arm_phys_hand.R', 'npc_ed_arm_phys_hand.L', 'npc_ed_arm_phys_forearm.fk.L', 'npc_ed_arm_phys_forearm.fk.R', 'npc_ed_arm_phys_upper_arm.fk.L', 'npc_ed_arm_phys_upper_arm.fk.R']
192
                 excludes = ['npc_ed_arm_phys_hand.R', 'npc_ed_arm_phys_hand.L', 'npc_ed_arm_phys_forearm.fk.L', 'npc_ed_arm_phys_forearm.fk.R', 'npc_ed_arm_phys_upper_arm.fk.L', 'npc_ed_arm_phys_upper_arm.fk.R']
193
+                #excludes = []
193
                 for x in physBody.groupMembers:
194
                 for x in physBody.groupMembers:
194
-                    print(x)
195
+                    print(x.name)
195
                                     
196
                                     
196
-                    if x not in excludes:
197
-                        x.applyForce([0,0,20], False)
197
+                    if x.name not in excludes:
198
+                        pass
199
+                        #x.applyForce([0,0,15], False)
200
+                    else:
201
+                        #x.applyForce([0,0,100], False)   
202
+                        pass 
203
+
198
                 scene.objects['npc_ed_arm_phys_master'].applyForce([0,0,500], False)
204
                 scene.objects['npc_ed_arm_phys_master'].applyForce([0,0,500], False)
205
+                scene.objects['npc_ed_arm_phys_head'].applyForce([0,0,400], False)
206
+                scene.objects['npc_ed_arm_phys_chest'].applyForce([0,0,200], False)
207
+                scene.objects['npc_ed_arm_phys_chest-1'].applyForce([0,0,200], False)
208
+                scene.objects['npc_ed_arm_phys_spine'].applyForce([0,0,200], False)
209
+                scene.objects['npc_ed_arm_phys_neck'].applyForce([0,0,200], False)
210
+                scene.objects['npc_ed_arm_phys_deltoid.L'].applyForce([0,0,200], False)
211
+                scene.objects['npc_ed_arm_phys_deltoid.R'].applyForce([0,0,200], False)
212
+                scene.objects['npc_ed_arm_phys_clavicle.L'].applyForce([0,0,200], False)
213
+                scene.objects['npc_ed_arm_phys_clavicle.R'].applyForce([0,0,200], False)
214
+
215
+            if dict['rUD'] > .08:
216
+                scene.objects['npc_ed_arm_phys_master'].applyForce([0,600,0], True)
199
         else:
217
         else:
200
             update_rb(own['rd_rb'], scene)   
218
             update_rb(own['rd_rb'], scene)   
201
             #pass
219
             #pass

+ 80
- 75
scripts/walker_states.py View File

17
 State = type("State", (object,), {})
17
 State = type("State", (object,), {})
18
 
18
 
19
 class State(object):
19
 class State(object):
20
-	def __init__(self, FSM):
21
-		self.FSM = FSM
20
+	def __init__(self, npcFSM):
21
+		self.npcFSM = npcFSM
22
 		self.timer = 0
22
 		self.timer = 0
23
 		self.startTime = 0
23
 		self.startTime = 0
24
 	def Enter(self):
24
 	def Enter(self):
32
 		#print('Exiting')
32
 		#print('Exiting')
33
 		
33
 		
34
 class Target1(State):
34
 class Target1(State):
35
-	def __init__(self,FSM):
36
-		super(Target1, self).__init__(FSM)    
35
+	def __init__(self,npcFSM):
36
+		super(Target1, self).__init__(npcFSM)    
37
 		
37
 		
38
 	def Enter(self):
38
 	def Enter(self):
39
 		#print('Preparing to walk towards target 1.')
39
 		#print('Preparing to walk towards target 1.')
40
 		self.cont = bge.logic.getCurrentController()
40
 		self.cont = bge.logic.getCurrentController()
41
-		self.FSM.stateLife = 1
41
+		self.npcFSM.stateLife = 1
42
 		self.own = self.cont.owner
42
 		self.own = self.cont.owner
43
 		self.target = 'larryTarget'
43
 		self.target = 'larryTarget'
44
 		self.npcArm = self.own.children['npc']
44
 		self.npcArm = self.own.children['npc']
60
 		super(Target1, self).Enter()
60
 		super(Target1, self).Enter()
61
 		
61
 		
62
 	def Execute(self):
62
 	def Execute(self):
63
-		#print('Tracking target 1.', self.FSM.stateLife)
64
-		self.FSM.stateLife += 1
63
+		#print('Tracking target 1.', self.npcFSM.stateLife)
64
+		self.npcFSM.stateLife += 1
65
 		duration = 500
65
 		duration = 500
66
-		if self.FSM.stateLife > duration:
66
+		if self.npcFSM.stateLife > duration:
67
 			num = randint(1,2)
67
 			num = randint(1,2)
68
 			if num == 1:
68
 			if num == 1:
69
-				self.FSM.ToTransition('toTarget2')
69
+				self.npcFSM.ToTransition('toTarget2')
70
 			elif num ==2:
70
 			elif num ==2:
71
-				self.FSM.ToTransition('toTarget3')	
71
+				self.npcFSM.ToTransition('toTarget3')	
72
 			else:
72
 			else:
73
-				self.FSM.ToTransition('toIdle')
73
+				self.npcFSM.ToTransition('toIdle')
74
 		else:	
74
 		else:	
75
 			self.cont.activate(self.actu)	
75
 			self.cont.activate(self.actu)	
76
 			self.npcArm.playAction('g_walk2', 1,62, layer=2, play_mode=0, speed=.5)			
76
 			self.npcArm.playAction('g_walk2', 1,62, layer=2, play_mode=0, speed=.5)			
80
 		self.cont.deactivate(self.actu) 
80
 		self.cont.deactivate(self.actu) 
81
 
81
 
82
 class Target2(State):
82
 class Target2(State):
83
-	def __init__(self,FSM):
84
-		super(Target2, self).__init__(FSM)    
83
+	def __init__(self,npcFSM):
84
+		super(Target2, self).__init__(npcFSM)    
85
 		
85
 		
86
 	def Enter(self):
86
 	def Enter(self):
87
 		#print('Preparing to walk towards target 2.')
87
 		#print('Preparing to walk towards target 2.')
88
 		self.cont = bge.logic.getCurrentController()
88
 		self.cont = bge.logic.getCurrentController()
89
-		self.FSM.stateLife = 1
89
+		self.npcFSM.stateLife = 1
90
 		self.own = self.cont.owner
90
 		self.own = self.cont.owner
91
 		self.target = 'larryTarget.001'
91
 		self.target = 'larryTarget.001'
92
 		self.npcArm = self.own.children['npc']
92
 		self.npcArm = self.own.children['npc']
104
 		super(Target2, self).Enter()
104
 		super(Target2, self).Enter()
105
 		
105
 		
106
 	def Execute(self):
106
 	def Execute(self):
107
-		#print('Tracking target 2.', self.FSM.stateLife)
108
-		self.FSM.stateLife += 1
107
+		#print('Tracking target 2.', self.npcFSM.stateLife)
108
+		self.npcFSM.stateLife += 1
109
 		duration = 1000
109
 		duration = 1000
110
-		if self.FSM.stateLife > duration:
110
+		if self.npcFSM.stateLife > duration:
111
 			num = randint(1,3)
111
 			num = randint(1,3)
112
 			if num == 1:
112
 			if num == 1:
113
-				self.FSM.ToTransition('toTarget1')
113
+				self.npcFSM.ToTransition('toTarget1')
114
 			elif num ==2:
114
 			elif num ==2:
115
-				self.FSM.ToTransition('toTarget3')	
115
+				self.npcFSM.ToTransition('toTarget3')	
116
 			else:
116
 			else:
117
-				self.FSM.ToTransition('toIdle')
117
+				self.npcFSM.ToTransition('toIdle')
118
 		else:		
118
 		else:		
119
 			self.cont.activate(self.actu)
119
 			self.cont.activate(self.actu)
120
 			self.npcArm.playAction('g_walk2', 1,62, layer=2, play_mode=0, speed=.5)			
120
 			self.npcArm.playAction('g_walk2', 1,62, layer=2, play_mode=0, speed=.5)			
125
 		self.cont.deactivate(self.actu)          
125
 		self.cont.deactivate(self.actu)          
126
 		
126
 		
127
 class Target3(State):
127
 class Target3(State):
128
-	def __init__(self,FSM):
129
-		super(Target3, self).__init__(FSM)    
128
+	def __init__(self,npcFSM):
129
+		super(Target3, self).__init__(npcFSM)    
130
 		
130
 		
131
 	def Enter(self):
131
 	def Enter(self):
132
 		#print('Preparing to walk towards target 3.')
132
 		#print('Preparing to walk towards target 3.')
133
 		self.cont = bge.logic.getCurrentController()
133
 		self.cont = bge.logic.getCurrentController()
134
-		self.FSM.stateLife = 1
134
+		self.npcFSM.stateLife = 1
135
 		self.own = self.cont.owner
135
 		self.own = self.cont.owner
136
 		self.target = 'larryTarget.002'
136
 		self.target = 'larryTarget.002'
137
 		self.npcArm = self.own.children['npc']
137
 		self.npcArm = self.own.children['npc']
149
 
149
 
150
 		
150
 		
151
 	def Execute(self):
151
 	def Execute(self):
152
-		self.FSM.stateLife += 1
152
+		self.npcFSM.stateLife += 1
153
 		duration = 1200
153
 		duration = 1200
154
-		if self.FSM.stateLife > duration:
154
+		if self.npcFSM.stateLife > duration:
155
 			if not (randint(1,3) % 2):
155
 			if not (randint(1,3) % 2):
156
-				self.FSM.ToTransition('toTarget1')
156
+				self.npcFSM.ToTransition('toTarget1')
157
 			else:
157
 			else:
158
-				self.FSM.ToTransition('toTarget2')
158
+				self.npcFSM.ToTransition('toTarget2')
159
 		else:
159
 		else:
160
 			cont = bge.logic.getCurrentController()
160
 			cont = bge.logic.getCurrentController()
161
 			own = cont.owner
161
 			own = cont.owner
170
 		
170
 		
171
 class Idle(State):
171
 class Idle(State):
172
 	
172
 	
173
-	def __init__(self,FSM):
174
-		super(Idle, self).__init__(FSM)  
173
+	def __init__(self,npcFSM):
174
+		super(Idle, self).__init__(npcFSM)  
175
 		
175
 		
176
 	def Enter(self):
176
 	def Enter(self):
177
 		#print('Starting to idle.')
177
 		#print('Starting to idle.')
178
 		self.cont = bge.logic.getCurrentController()
178
 		self.cont = bge.logic.getCurrentController()
179
 		self.own = self.cont.owner
179
 		self.own = self.cont.owner
180
 		self.npcArm = self.own.children['npc']
180
 		self.npcArm = self.own.children['npc']
181
-		self.FSM.stateLife = 1
181
+		self.npcFSM.stateLife = 1
182
 
182
 
183
 		super(Idle, self).Enter()
183
 		super(Idle, self).Enter()
184
 		
184
 		
185
 	def Execute(self):
185
 	def Execute(self):
186
-		#print('Idleing.', self.FSM.stateLife)
187
-		self.FSM.stateLife += 1
186
+		#print('Idleing.', self.npcFSM.stateLife)
187
+		self.npcFSM.stateLife += 1
188
 		duration = 300
188
 		duration = 300
189
-		if self.FSM.stateLife > duration:
189
+		if self.npcFSM.stateLife > duration:
190
 			#num = randint(1,4)
190
 			#num = randint(1,4)
191
-			self.FSM.ToTransition('toTarget1')
191
+			self.npcFSM.ToTransition('toImpatient')
192
 			# if num == 1:
192
 			# if num == 1:
193
-			# 	self.FSM.ToTransition('toTarget1')
193
+			# 	self.npcFSM.ToTransition('toTarget1')
194
 			# elif num == 2:
194
 			# elif num == 2:
195
-			# 	self.FSM.ToTransition('toTarget2')	
195
+			# 	self.npcFSM.ToTransition('toTarget2')	
196
 			# elif num == 3:
196
 			# elif num == 3:
197
-			# 	self.FSM.ToTransition('toTarget3')
197
+			# 	self.npcFSM.ToTransition('toTarget3')
198
 			# elif num == 4 or num == 5 or num == 6:
198
 			# elif num == 4 or num == 5 or num == 6:
199
-			# 	self.FSM.ToTransition('toImpatient')										
199
+			# 	self.npcFSM.ToTransition('toImpatient')										
200
 			# else:
200
 			# else:
201
-			# 	self.FSM.ToTransition('toIdle')
201
+			# 	self.npcFSM.ToTransition('toIdle')
202
 		else:
202
 		else:
203
 			#pass
203
 			#pass
204
 			#print(self.own.children)
204
 			#print(self.own.children)
205
+			#print('idling')
205
 			self.npcArm.playAction('g_idle', 1,201, layer=2, play_mode=0, speed=.5)	
206
 			self.npcArm.playAction('g_idle', 1,201, layer=2, play_mode=0, speed=.5)	
206
 			
207
 			
207
 	def Exit(self):
208
 	def Exit(self):
211
 
212
 
212
 class Startup(State):
213
 class Startup(State):
213
 	
214
 	
214
-	def __init__(self,FSM):
215
-		super(Startup, self).__init__(FSM)  
215
+	def __init__(self,npcFSM):
216
+		super(Startup, self).__init__(npcFSM)  
216
 		
217
 		
217
 	def Enter(self):
218
 	def Enter(self):
218
-		self.FSM.stateLife = 1
219
+		self.npcFSM.stateLife = 1
220
+		print('npc startup enter')
219
 		super(Startup, self).Enter()
221
 		super(Startup, self).Enter()
220
 		
222
 		
221
 	def Execute(self):
223
 	def Execute(self):
222
-		self.FSM.stateLife += 1
224
+		self.npcFSM.stateLife += 1
223
 		duration = 4
225
 		duration = 4
224
-		if self.FSM.stateLife > duration:
225
-				self.FSM.ToTransition('toIdle')
226
+		#print('executing', self.npcFSM.stateLife)
227
+		if self.npcFSM.stateLife > duration:
228
+				self.npcFSM.ToTransition('toIdle')
226
 			
229
 			
227
 	def Exit(self):
230
 	def Exit(self):
228
 		#pass
231
 		#pass
230
 
233
 
231
 class Impatient(State):
234
 class Impatient(State):
232
 	
235
 	
233
-	def __init__(self,FSM):
234
-		super(Impatient, self).__init__(FSM)  
236
+	def __init__(self,npcFSM):
237
+		super(Impatient, self).__init__(npcFSM)  
235
 		
238
 		
236
 	def Enter(self):
239
 	def Enter(self):
237
 		#print('Starting to idle.')
240
 		#print('Starting to idle.')
238
-		self.FSM.stateLife = 1
241
+		self.npcFSM.stateLife = 1
239
 		self.cont = bge.logic.getCurrentController()
242
 		self.cont = bge.logic.getCurrentController()
240
 		self.own = self.cont.owner
243
 		self.own = self.cont.owner
241
 		self.npcArm = self.own.children['npc']	
244
 		self.npcArm = self.own.children['npc']	
242
 		super(Impatient, self).Enter()
245
 		super(Impatient, self).Enter()
243
 		
246
 		
244
 	def Execute(self):
247
 	def Execute(self):
245
-		##print('being Impatient.', self.FSM.stateLife)
246
-		self.FSM.stateLife += 1
248
+		#print('being Impatient.', self.npcFSM.stateLife)
249
+		self.npcFSM.stateLife += 1
247
 		duration = 300
250
 		duration = 300
248
-		if self.FSM.stateLife > duration:
249
-			self.FSM.ToTransition('toIdle')
251
+		if self.npcFSM.stateLife > duration:
252
+			self.npcFSM.ToTransition('toIdle')
250
 		else:
253
 		else:
251
-			pass
252
-			#self.npcArm.playAction('npcImpatient', 1,201, layer=2, play_mode=0, speed=.5)	
254
+			#pass
255
+			self.npcArm.playAction('npcImpatient', 1,201, layer=2, play_mode=0, speed=.5)	
253
 			
256
 			
254
 	def Exit(self):
257
 	def Exit(self):
255
 		pass
258
 		pass
259
 #===================================
262
 #===================================
260
 						
263
 						
261
 
264
 
262
-class FSM(object):
265
+class npcFSM(object):
263
 	def __init__ (self, character):
266
 	def __init__ (self, character):
264
 		self.char = character
267
 		self.char = character
265
 		self.states = {}
268
 		self.states = {}
296
 
299
 
297
 class Walker(Char):
300
 class Walker(Char):
298
 	def __init__(self):
301
 	def __init__(self):
299
-		self.FSM = FSM(self)
302
+		self.npcFSM = npcFSM(self)
300
 		#cont = bge.logic.getCurrentController()
303
 		#cont = bge.logic.getCurrentController()
301
 		#own = cont.owner
304
 		#own = cont.owner
302
 		#self.LightOn = own['state']
305
 		#self.LightOn = own['state']
303
 		
306
 		
304
 		##STATES
307
 		##STATES
305
-		self.FSM.AddState("Startup", Startup(self.FSM))
306
-		self.FSM.AddState("Idle", Idle(self.FSM))
307
-		self.FSM.AddState("Impatient", Impatient(self.FSM))
308
-		self.FSM.AddState('Target1', Target1(self.FSM))
309
-		self.FSM.AddState('Target3', Target3(self.FSM))
310
-		self.FSM.AddState('Target2', Target2(self.FSM))
308
+		self.npcFSM.AddState("Startup", Startup(self.npcFSM))
309
+		self.npcFSM.AddState("Idle", Idle(self.npcFSM))
310
+		self.npcFSM.AddState("Impatient", Impatient(self.npcFSM))
311
+		#self.npcFSM.AddState('Target1', Target1(self.npcFSM))
312
+		#self.npcFSM.AddState('Target3', Target3(self.npcFSM))
313
+		#self.npcFSM.AddState('Target2', Target2(self.npcFSM))
311
 		
314
 		
312
 		#TRANSITIONS
315
 		#TRANSITIONS
313
-		self.FSM.AddTransition('toStartup', Transition('Startup'))
314
-		self.FSM.AddTransition('toIdle', Transition('Idle'))
315
-		self.FSM.AddTransition('toImpatient', Transition('Impatient'))
316
-		self.FSM.AddTransition('toTarget3', Transition('Target3'))
317
-		self.FSM.AddTransition('toTarget1', Transition('Target1'))
318
-		self.FSM.AddTransition('toTarget2', Transition('Target2'))
316
+		self.npcFSM.AddTransition('toStartup', Transition('Startup'))
317
+		self.npcFSM.AddTransition('toIdle', Transition('Idle'))
318
+		self.npcFSM.AddTransition('toImpatient', Transition('Impatient'))
319
+		#self.npcFSM.AddTransition('toTarget3', Transition('Target3'))
320
+		#self.npcFSM.AddTransition('toTarget1', Transition('Target1'))
321
+		#self.npcFSM.AddTransition('toTarget2', Transition('Target2'))
319
 		
322
 		
320
 		
323
 		
321
-		if self.FSM.curState == None:
322
-			self.FSM.SetState('Startup')
323
-			#self.FSM.ToTransition('toIdle')
324
-			#print('setting none')
324
+		if self.npcFSM.curState == None:
325
+			self.npcFSM.SetState('Startup')
326
+			#self.npcFSM.ToTransition('toIdle')
327
+			#print('setting npc state to startup')
325
 	
328
 	
326
 	def Execute(self):
329
 	def Execute(self):
327
-		self.FSM.Execute()    
330
+		self.npcFSM.Execute()    
331
+		#print('executing machine')
328
 #====================================     
332
 #====================================     
329
 r = Walker()
333
 r = Walker()
330
 def main(cont):
334
 def main(cont):
348
 		if ln in scene.objects:
352
 		if ln in scene.objects:
349
 			to = scene.objects[ln]	
353
 			to = scene.objects[ln]	
350
 			own.worldPosition = to.worldPosition
354
 			own.worldPosition = to.worldPosition
355
+			own.worldOrientation = to.worldOrientation
351
 			#own.worldPosition.z += 50
356
 			#own.worldPosition.z += 50
352
 
357
 
353
 
358
 
354
-	#r.Execute()    
355
-	##print(r.FSM.curState)
359
+	r.Execute()    
360
+	#print(r.npcFSM.curState)
356
 
361
 
357
 
362
 
358
 	own['frame'] += 1
363
 	own['frame'] += 1

Loading…
Cancel
Save