Monday, 18 January 2010

Ragdoll Zombie

Ragdolls are pretty fun to mess around with, but something I've yet to see much is using them with expression 2's applyForce in almost any fashion. So I've been putting together a basic little thing that may become the new Hel or Loki drone for Valhalla.

Basically, you plant this code onto any ragdoll (Preferably a human HL2 character because that's what the variables are based on and they're pretty consistent), the ragdoll hops up and starts following you. The name comes from the brief programming that self-destructs the E2 chip if you open fire on the zombie's head (Though the chip itself is also fair game); anywhere else and it just keeps coming. It's a work in progress so there's a few kinks to it (Like being able to kill a zombie from across the map with the crowbar...).

As I said this might be the basis for a drone, so there's a little droid head that also shows up above the ragdoll and stares at you, the end product might float the E2 inside the head and search for ragdolls to use as "human shields" for itself.

Code:
@name Ragdoll Zombie prototype
@persist E:entity N Mass Z BC

if(first()){
E=entity():isWeldedTo()
BC=E:boneCount()
entity():setAlpha(255)
entity():setMass(0)

OT=owner():toWorld(owner():boxMax()):z()
OB=owner():toWorld(owner():boxMin()):z()
Z=(OT-OB)

#Pelvis = 0
#Torso = 1
#RShoulder = 2
#LShoulder = 3
#LElbow = 4
#LHand = 5
#RElbow = 6
#RHand = 7
#Hip = 8
#Knee = 9
#Head = 10

Ang=array() Col=array() Mod=array() Par=array() Pos=array() Sca=array()
Ang:pushAngle(ang()) Col:pushVector(vec(1,1,1)*255) Mod:pushString("hqicosphere2") Par:pushNumber(0) Pos:pushVector(vec(0,0,23)) Sca:pushVector(vec(2,1.5,1)/2)
Ang:pushAngle(ang()) Col:pushVector(vec(0,1,1)*255) Mod:pushString("dome2") Par:pushNumber(1) Pos:pushVector(vec(2,0,25)) Sca:pushVector(vec(2,2,1)/2)
Ang:pushAngle(ang(-22.5,0,0)) Col:pushVector(vec(0,1,1)*255) Mod:pushString("dome2") Par:pushNumber(1) Pos:pushVector(vec(-1,0,24)) Sca:pushVector(vec(2,2,1)/2)
Ang:pushAngle(ang(-45,0,0)) Col:pushVector(vec(0,1,1)*255) Mod:pushString("dome2") Par:pushNumber(1) Pos:pushVector(vec(-3,0,23)) Sca:pushVector(vec(2,2,1)/2)
Ang:pushAngle(ang(90,0,0)) Col:pushVector(vec(0,1,1)*255) Mod:pushString("hqcylinder") Par:pushNumber(1) Pos:pushVector(vec(2,0,23)) Sca:pushVector(vec(1,1,3)/4)
M=0
while(M<=Ang:count()){
P=Pos[M,vector]+E:bone(10):pos()
S=Sca[M,vector]
A=Ang[M,angle]
C=Col[M,vector]
Mo=Mod[M,string]

holoCreate(M,P,S,A,C)
holoModel(M,Mo)
if(Par[M,number]){holoParent(M,Par[M,number])}
M++
}
runOnTick(1)
}

while(N<=BC){
B=E:bone(N)
Mass+=B:mass()
N++
}

rangerFilter(E)
Ground=rangerOffset(2000,E:bone(1):massCenter(),vec(0,0,-1)):position()

O=owner():toWorld(owner():boxCenter())
Po=Ground+vec(0,0,Z-7)
Vec=(Po-E:bone(1):massCenter())*(Mass+20)
E:bone(1):applyForce(Vec)
E:bone(1):applyForce((owner():pos()-E:bone(1):pos()):normalized()*50)

Po=E:bone(1):pos()+vec(0,0,10)
Vec=(Po-E:bone(10):massCenter())*E:bone(10):mass()
E:bone(10):applyForce(Vec)
Skull=E:bone(10):pos():setZ((E:toWorld(E:boxMax())+vec(0,0,5)):z())
holoPos(1,Skull)
holoAng(1,(owner():shootPos()-holoEntity(1):pos()):toAngle())

Po=E:bone(1):pos()-vec(0,0,10)
Vec=(Po-E:bone(0):massCenter())*E:bone(0):mass()
E:bone(0):applyForce(Vec)
E:bone(0):applyForce((owner():pos()-E:bone(0):pos()):normalized()*50)

if((owner():aimBone()==E:bone(10)|owner():aimEntity()==entity())
& owner():keyAttack1()){
selfDestruct()
}

No comments:

Post a Comment