Browse Source

npc rebirth

shuvit 1 month 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,7 +16,7 @@ PAF = 0
16 16
 DAF = 0
17 17
 
18 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 20
 deck = dict['spawned_npc_decks'][npc_index]
21 21
 trucks = dict['spawned_npc_trucks'][npc_index]
22 22
 #deck = scene.objects[deck]
@@ -166,7 +166,8 @@ def loadData(cont, own):
166 166
                 deck.worldPosition = position
167 167
                 trucks.worldPosition = position                   
168 168
                 
169
-        except:
169
+        except Exception as e:
170
+            print(e)
170 171
             print('npc positioning not working')
171 172
             #pass
172 173
     #-----Orientation-----#

+ 21
- 3
scripts/ragdoll.py View File

@@ -190,12 +190,30 @@ def main():
190 190
             if dict['lUD'] < -.08:
191 191
                 physBody = own['rd_rb']
192 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 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 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 217
         else:
200 218
             update_rb(own['rd_rb'], scene)   
201 219
             #pass

+ 80
- 75
scripts/walker_states.py View File

@@ -17,8 +17,8 @@ class Transition(object):
17 17
 State = type("State", (object,), {})
18 18
 
19 19
 class State(object):
20
-	def __init__(self, FSM):
21
-		self.FSM = FSM
20
+	def __init__(self, npcFSM):
21
+		self.npcFSM = npcFSM
22 22
 		self.timer = 0
23 23
 		self.startTime = 0
24 24
 	def Enter(self):
@@ -32,13 +32,13 @@ class State(object):
32 32
 		#print('Exiting')
33 33
 		
34 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 38
 	def Enter(self):
39 39
 		#print('Preparing to walk towards target 1.')
40 40
 		self.cont = bge.logic.getCurrentController()
41
-		self.FSM.stateLife = 1
41
+		self.npcFSM.stateLife = 1
42 42
 		self.own = self.cont.owner
43 43
 		self.target = 'larryTarget'
44 44
 		self.npcArm = self.own.children['npc']
@@ -60,17 +60,17 @@ class Target1(State):
60 60
 		super(Target1, self).Enter()
61 61
 		
62 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 65
 		duration = 500
66
-		if self.FSM.stateLife > duration:
66
+		if self.npcFSM.stateLife > duration:
67 67
 			num = randint(1,2)
68 68
 			if num == 1:
69
-				self.FSM.ToTransition('toTarget2')
69
+				self.npcFSM.ToTransition('toTarget2')
70 70
 			elif num ==2:
71
-				self.FSM.ToTransition('toTarget3')	
71
+				self.npcFSM.ToTransition('toTarget3')	
72 72
 			else:
73
-				self.FSM.ToTransition('toIdle')
73
+				self.npcFSM.ToTransition('toIdle')
74 74
 		else:	
75 75
 			self.cont.activate(self.actu)	
76 76
 			self.npcArm.playAction('g_walk2', 1,62, layer=2, play_mode=0, speed=.5)			
@@ -80,13 +80,13 @@ class Target1(State):
80 80
 		self.cont.deactivate(self.actu) 
81 81
 
82 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 86
 	def Enter(self):
87 87
 		#print('Preparing to walk towards target 2.')
88 88
 		self.cont = bge.logic.getCurrentController()
89
-		self.FSM.stateLife = 1
89
+		self.npcFSM.stateLife = 1
90 90
 		self.own = self.cont.owner
91 91
 		self.target = 'larryTarget.001'
92 92
 		self.npcArm = self.own.children['npc']
@@ -104,17 +104,17 @@ class Target2(State):
104 104
 		super(Target2, self).Enter()
105 105
 		
106 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 109
 		duration = 1000
110
-		if self.FSM.stateLife > duration:
110
+		if self.npcFSM.stateLife > duration:
111 111
 			num = randint(1,3)
112 112
 			if num == 1:
113
-				self.FSM.ToTransition('toTarget1')
113
+				self.npcFSM.ToTransition('toTarget1')
114 114
 			elif num ==2:
115
-				self.FSM.ToTransition('toTarget3')	
115
+				self.npcFSM.ToTransition('toTarget3')	
116 116
 			else:
117
-				self.FSM.ToTransition('toIdle')
117
+				self.npcFSM.ToTransition('toIdle')
118 118
 		else:		
119 119
 			self.cont.activate(self.actu)
120 120
 			self.npcArm.playAction('g_walk2', 1,62, layer=2, play_mode=0, speed=.5)			
@@ -125,13 +125,13 @@ class Target2(State):
125 125
 		self.cont.deactivate(self.actu)          
126 126
 		
127 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 131
 	def Enter(self):
132 132
 		#print('Preparing to walk towards target 3.')
133 133
 		self.cont = bge.logic.getCurrentController()
134
-		self.FSM.stateLife = 1
134
+		self.npcFSM.stateLife = 1
135 135
 		self.own = self.cont.owner
136 136
 		self.target = 'larryTarget.002'
137 137
 		self.npcArm = self.own.children['npc']
@@ -149,13 +149,13 @@ class Target3(State):
149 149
 
150 150
 		
151 151
 	def Execute(self):
152
-		self.FSM.stateLife += 1
152
+		self.npcFSM.stateLife += 1
153 153
 		duration = 1200
154
-		if self.FSM.stateLife > duration:
154
+		if self.npcFSM.stateLife > duration:
155 155
 			if not (randint(1,3) % 2):
156
-				self.FSM.ToTransition('toTarget1')
156
+				self.npcFSM.ToTransition('toTarget1')
157 157
 			else:
158
-				self.FSM.ToTransition('toTarget2')
158
+				self.npcFSM.ToTransition('toTarget2')
159 159
 		else:
160 160
 			cont = bge.logic.getCurrentController()
161 161
 			own = cont.owner
@@ -170,38 +170,39 @@ class Target3(State):
170 170
 		
171 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 176
 	def Enter(self):
177 177
 		#print('Starting to idle.')
178 178
 		self.cont = bge.logic.getCurrentController()
179 179
 		self.own = self.cont.owner
180 180
 		self.npcArm = self.own.children['npc']
181
-		self.FSM.stateLife = 1
181
+		self.npcFSM.stateLife = 1
182 182
 
183 183
 		super(Idle, self).Enter()
184 184
 		
185 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 188
 		duration = 300
189
-		if self.FSM.stateLife > duration:
189
+		if self.npcFSM.stateLife > duration:
190 190
 			#num = randint(1,4)
191
-			self.FSM.ToTransition('toTarget1')
191
+			self.npcFSM.ToTransition('toImpatient')
192 192
 			# if num == 1:
193
-			# 	self.FSM.ToTransition('toTarget1')
193
+			# 	self.npcFSM.ToTransition('toTarget1')
194 194
 			# elif num == 2:
195
-			# 	self.FSM.ToTransition('toTarget2')	
195
+			# 	self.npcFSM.ToTransition('toTarget2')	
196 196
 			# elif num == 3:
197
-			# 	self.FSM.ToTransition('toTarget3')
197
+			# 	self.npcFSM.ToTransition('toTarget3')
198 198
 			# elif num == 4 or num == 5 or num == 6:
199
-			# 	self.FSM.ToTransition('toImpatient')										
199
+			# 	self.npcFSM.ToTransition('toImpatient')										
200 200
 			# else:
201
-			# 	self.FSM.ToTransition('toIdle')
201
+			# 	self.npcFSM.ToTransition('toIdle')
202 202
 		else:
203 203
 			#pass
204 204
 			#print(self.own.children)
205
+			#print('idling')
205 206
 			self.npcArm.playAction('g_idle', 1,201, layer=2, play_mode=0, speed=.5)	
206 207
 			
207 208
 	def Exit(self):
@@ -211,18 +212,20 @@ class Idle(State):
211 212
 
212 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 218
 	def Enter(self):
218
-		self.FSM.stateLife = 1
219
+		self.npcFSM.stateLife = 1
220
+		print('npc startup enter')
219 221
 		super(Startup, self).Enter()
220 222
 		
221 223
 	def Execute(self):
222
-		self.FSM.stateLife += 1
224
+		self.npcFSM.stateLife += 1
223 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 230
 	def Exit(self):
228 231
 		#pass
@@ -230,26 +233,26 @@ class Startup(State):
230 233
 
231 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 239
 	def Enter(self):
237 240
 		#print('Starting to idle.')
238
-		self.FSM.stateLife = 1
241
+		self.npcFSM.stateLife = 1
239 242
 		self.cont = bge.logic.getCurrentController()
240 243
 		self.own = self.cont.owner
241 244
 		self.npcArm = self.own.children['npc']	
242 245
 		super(Impatient, self).Enter()
243 246
 		
244 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 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 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 257
 	def Exit(self):
255 258
 		pass
@@ -259,7 +262,7 @@ class Impatient(State):
259 262
 #===================================
260 263
 						
261 264
 
262
-class FSM(object):
265
+class npcFSM(object):
263 266
 	def __init__ (self, character):
264 267
 		self.char = character
265 268
 		self.states = {}
@@ -296,35 +299,36 @@ Char = type("Char",(object,),{})
296 299
 
297 300
 class Walker(Char):
298 301
 	def __init__(self):
299
-		self.FSM = FSM(self)
302
+		self.npcFSM = npcFSM(self)
300 303
 		#cont = bge.logic.getCurrentController()
301 304
 		#own = cont.owner
302 305
 		#self.LightOn = own['state']
303 306
 		
304 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 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 329
 	def Execute(self):
327
-		self.FSM.Execute()    
330
+		self.npcFSM.Execute()    
331
+		#print('executing machine')
328 332
 #====================================     
329 333
 r = Walker()
330 334
 def main(cont):
@@ -348,11 +352,12 @@ def main(cont):
348 352
 		if ln in scene.objects:
349 353
 			to = scene.objects[ln]	
350 354
 			own.worldPosition = to.worldPosition
355
+			own.worldOrientation = to.worldOrientation
351 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 363
 	own['frame'] += 1

Loading…
Cancel
Save