The war with the ragdoll goes as follows: it is impossible to restore an animation when the character is hit by a vehicle and gets back on its feet. This is because the commands SetPosition, GetRotation in LE 4.6 produce a death shudder, like a déjà vu in the best style of the matrix, I do not know if to say that it convulses, or is possessed. For that reason it is better to use SetParent, this implies not being able to make the restoration in the best style of GTA V.
This cannot be done.
https://thumbs.gfycat.com/FlickeringOrderlyAplomadofalcon-size_restricted.gif
https://thumbs.gfycat.com/HeartyMistyIberianmole-max-1mb.gif
Then, the ragdoll, it will only be possible to unleash the death of the character. And you can reset the character without problems, to return it to a checkpoint to continue the game.
https://j.gifs.com/J6j5ny.gif
Closed case.
--||########################################||
--|| Proyecto : Mars. ||
--|| Programador : Yue Rexie. ||
--|| Fichero : CRagdoll.lua. ||
--||########################################||
--|| Notas : Clase CPRagdoll que ||
--|| crea el objeto Ragdoll ||
--||########################################||
CRagdoll={}
function CRagdoll:Create(entity)
local this={}
this.window = nil
this.world = nil
this.player = nil
this.r = nil
this.bHead = nil
this.bThorax = nil
this.bStomach = nil
this.bNavel = nil
this.bPelvis = nil
function this:Start()
self.window = Window:GetCurrent()
self.world = World:GetCurrent()
self.player = entity
self.r = false
self:GetBones()
self:GetBodies()
end
function this:GetBones()
--**Trunk**
self.bHead = self.player:FindChild("mixamorig:Head")
self.bThorax = self.player:FindChild("mixamorig:Spine2")
self.bStomach = self.player:FindChild("mixamorig:Spine1")
self.bNavel = self.player:FindChild("mixamorig:Spine")
self.bPelvis = self.player:FindChild("mixamorig:Hips")
--**Arms**
self.bRShoul = self.player:FindChild("mixamorig:RightArm")
self.bRArm = self.player:FindChild("mixamorig:RightForeArm")
self.bRHand = self.player:FindChild("mixamorig:RightHand")
self.bLShoul = self.player:FindChild("mixamorig:LeftArm")
self.bLArm = self.player:FindChild("mixamorig:LeftForeArm")
self.bLHand = self.player:FindChild("mixamorig:LeftHand")
--**Legs**
self.bRLeg = self.player:FindChild("mixamorig:RightUpLeg")
self.bRKnee = self.player:FindChild("mixamorig:RightLeg")
self.bLLeg = self.player:FindChild("mixamorig:LeftUpLeg")
self.bLKnee = self.player:FindChild("mixamorig:LeftLeg")
end
function this:GetBodies()
--**Trunk**
self.mHead = self.world:FindEntity("BodyHead")
self.mThorax = self.world:FindEntity("BodyThorax")
self.mStomach = self.world:FindEntity("BodyStomach")
self.mNavel = self.world:FindEntity("BodyNavel")
self.mPelvis = self.world:FindEntity("BodyPelvis")
--**Arms**
self.mRShoul = self.world:FindEntity("BodyRShoul")
self.mRArm = self.world:FindEntity("BodyRArm")
self.mRHand = self.world:FindEntity("BodyRHand")
self.mLShoul = self.world:FindEntity("BodyLShoul")
self.mLArm = self.world:FindEntity("BodyLArm")
self.mLHand = self.world:FindEntity("BodyLHand")
--**Legs**
self.mRLeg = self.world:FindEntity("BodyRLeg")
self.mRKnee = self.world:FindEntity("BodyRKnee")
self.mLLeg = self.world:FindEntity("BodyLLeg")
self.mLKnee = self.world:FindEntity("BodyLKnee")
end
function this:SetPosition()
--**Trunk**
self.mHead:SetPosition(self.bHead:GetPosition(true),true)
self.mThorax:SetPosition(self.bThorax:GetPosition(true),true)
self.mStomach:SetPosition(self.bStomach:GetPosition(true),true)
self.mNavel:SetPosition(self.bNavel:GetPosition(true),true)
self.mPelvis:SetPosition(self.bPelvis:GetPosition(true),true)
--**Arms**
self.mRShoul:SetPosition(self.bRShoul:GetPosition(true),true)
self.mRArm:SetPosition(self.bRArm:GetPosition(true),true)
self.mRHand:SetPosition(self.bRHand:GetPosition(true),true)
self.mLShoul:SetPosition(self.bLShoul:GetPosition(true),true)
self.mLArm:SetPosition(self.bLArm:GetPosition(true),true)
self.mLHand:SetPosition(self.bLHand:GetPosition(true),true)
--**Legs**
self.mRLeg:SetPosition(self.bRLeg:GetPosition(true),true)
self.mRKnee:SetPosition(self.bRKnee:GetPosition(true),true)
self.mLLeg:SetPosition(self.bLLeg:GetPosition(true),true)
self.mLKnee:SetPosition(self.bLKnee:GetPosition(true),true)
end
function this:SetRotation()
--**Trunk**
self.mHead:SetRotation(self.bHead:GetRotation(true),true)
self.mThorax:SetRotation(self.bThorax:GetRotation(true),true)
self.mStomach:SetRotation(self.bStomach:GetRotation(true),true)
self.mNavel:SetRotation(self.bNavel:GetRotation(true),true)
self.mPelvis:SetRotation(self.bPelvis:GetRotation(true),true)
--**Arms**
self.mRShoul:SetRotation(self.bRShoul:GetRotation(true),true)
self.mRArm:SetRotation(self.bRArm:GetRotation(true),true)
self.mRHand:SetRotation(self.bRHand:GetRotation(true),true)
self.mLShoul:SetRotation(self.bLShoul:GetRotation(true),true)
self.mLArm:SetRotation(self.bLArm:GetRotation(true),true)
self.mLHand:SetRotation(self.bLHand:GetRotation(true),true)
--**Legs**
self.mRLeg:SetRotation(self.bRLeg:GetRotation(true),true)
self.mRKnee:SetRotation(self.bRKnee:GetRotation(true),true)
self.mLLeg:SetRotation(self.bLLeg:GetRotation(true),true)
self.mLKnee:SetRotation(self.bLKnee:GetRotation(true),true)
end
function this:CreateJoints()
--**Trunk**
self.jThoraxHead = Joint:Ball(self.bHead:GetPosition(true).x, self.bHead:GetPosition(true).y, self.bHead:GetPosition(true).z, self.mThorax, self.mHead)
self.jThoraxHead:EnableLimits()
self.jThoraxHead:SetLimits(45,45)
self.jStomachThorax = Joint:Hinge(self.mThorax:GetPosition(true).x, self.mThorax:GetPosition(true).y, self.mThorax:GetPosition(true).z,1,0,0, self.mStomach, self.mThorax )
self.jStomachThorax:EnableLimits()
self.jStomachThorax:SetLimits(-5,15)
self.jNavelStomach = Joint:Hinge(self.mStomach:GetPosition(true).x, self.mStomach:GetPosition(true).y, self.mStomach:GetPosition(true).z, 1,0,0, self.mNavel, self.mStomach )
self.jNavelStomach:EnableLimits()
self.jNavelStomach:SetLimits(-5,15)
self.jPelvisNavel = Joint:Hinge( self.mNavel:GetPosition(true).x, self.mNavel:GetPosition(true).y, self.mNavel:GetPosition(true).z, 1,0,0, self.mPelvis, self.mNavel )
self.jPelvisNavel:EnableLimits()
self.jPelvisNavel:SetLimits(-5,15)
--**Arms**
self.jRShoulThorax = Joint:Ball(self.bRShoul:GetPosition(true).x, self.bRShoul:GetPosition(true).y, self.bRShoul:GetPosition(true).z, self.mRShoul, self.mThorax)
self.jRShoulThorax:EnableLimits()
self.jRShoulThorax:SetLimits(90,90)
self.jRArmShoul = Joint:Hinge(self.bRArm:GetPosition(true).x, self.bRArm:GetPosition(true).y, self.bRArm:GetPosition(true).z, 0,1,0, self.mRArm, self.mRShoul )
self.jRArmShoul:EnableLimits()
self.jRArmShoul:SetLimits(-90,0)
self.jRHandArm = Joint:Hinge(self.bRHand:GetPosition(true).x, self.bRHand:GetPosition(true).y, self.bRHand:GetPosition(true).z, 0,0,1, self.mRHand, self.mRArm )
self.jRHandArm:EnableLimits()
self.jRHandArm:SetLimits(-55,55)
self.jLShoulThorax = Joint:Ball(self.bLShoul:GetPosition(true).x, self.bLShoul:GetPosition(true).y, self.bLShoul:GetPosition(true).z, self.mLShoul, self.mThorax)
self.jLShoulThorax:EnableLimits()
self.jLShoulThorax:SetLimits(90,90)
self.jLArmShoul = Joint:Hinge(self.bLArm:GetPosition(true).x, self.bLArm:GetPosition(true).y, self.bLArm:GetPosition(true).z, 0,1,0, self.mLArm, self.mLShoul )
self.jLArmShoul:EnableLimits()
self.jLArmShoul:SetLimits(0,-90)
self.jLHandArm = Joint:Hinge(self.bLHand:GetPosition(true).x, self.bLHand:GetPosition(true).y, self.bLHand:GetPosition(true).z, 0,0,1, self.mLHand, self.mLArm )
self.jLHandArm:EnableLimits()
self.jLHandArm:SetLimits(-55,55)
--**Legs**
self.jRLegPelvis = Joint:Ball(self.bPelvis:GetPosition(true).x, self.bPelvis:GetPosition(true).y, self.bPelvis:GetPosition(true).z, self.mRLeg, self.mPelvis )
self.jRLegPelvis:EnableLimits()
self.jRLegPelvis:SetLimits(10,90)
self.jRKneeLeg = Joint:Hinge(self.bRKnee:GetPosition(true).x, self.bRKnee:GetPosition(true).y, self.bRKnee:GetPosition(true).z, 1,0,0, self.mRKnee, self.mRLeg )
self.jRKneeLeg:EnableLimits()
self.jRKneeLeg:SetLimits(-90,0)
self.jLLegPelvis = Joint:Ball(self.bPelvis:GetPosition(true).x, self.bPelvis:GetPosition(true).y, self.bPelvis:GetPosition(true).z, self.mLLeg, self.mPelvis )
self.jLLegPelvis:EnableLimits()
self.jLLegPelvis:SetLimits(10,90)
self.jLKneeLeg = Joint:Hinge(self.bLKnee:GetPosition(true).x, self.bLKnee:GetPosition(true).y, self.bLKnee:GetPosition(true).z, 1,0,0, self.mLKnee, self.mLLeg )
self.jLKneeLeg:EnableLimits()
self.jLKneeLeg:SetLimits(-90,0)
end
function this:DestroyJoints()
--**Trunk**
self.jThoraxHead:Release()
self.jStomachThorax:Release()
self.jNavelStomach:Release()
self.jPelvisNavel:Release()
--**Arms**
self.jRShoulThorax:Release()
self.jRArmShoul:Release()
self.jRHandArm:Release()
self.jLShoulThorax:Release()
self.jLArmShoul:Release()
self.jLHandArm:Release()
--**Legs**
self.jRLegPelvis:Release()
self.jRKneeLeg:Release()
self.jLLegPelvis:Release()
self.jLKneeLeg:Release()
end
function this:SetMass(mass)
--**Trunk**
self.mHead:SetMass(mass)
self.mThorax:SetMass(mass)
self.mStomach:SetMass(mass)
self.mNavel:SetMass(mass)
self.mPelvis:SetMass(mass)
--**Arms**
self.mRShoul:SetMass(mass)
self.mRArm:SetMass(mass)
self.mRHand:SetMass(mass)
self.mLShoul:SetMass(mass)
self.mLArm:SetMass(mass)
self.mLHand:SetMass(mass)
--**Legs**
self.mRLeg:SetMass(mass)
self.mRKnee:SetMass(mass)
self.mLLeg:SetMass(mass)
self.mLKnee:SetMass(mass)
end
function this:UpdateBones()
self.bHead:SetPosition(self.mHead:GetPosition(true),true)
self.bHead:SetRotation(self.mHead:GetRotation(true),true)
self.bThorax:SetPosition(self.mThorax:GetPosition(true),true)
self.bThorax:SetRotation(self.mThorax:GetRotation(true),true)
self.bStomach:SetPosition(self.mStomach:GetPosition(true),true)
self.bStomach:SetRotation(self.mStomach:GetRotation(true),true)
end
function this:SetParent()
--**Trunk**
self.bHead:SetParent(self.mHead,true)
self.bThorax:SetParent(self.mThorax,true)
self.bStomach:SetParent(self.mStomach,true)
self.bNavel:SetParent(self.mNavel,true)
self.bPelvis:SetParent(self.mPelvis,true)
--**Arms**
self.bRShoul:SetParent(self.mRShoul,true)
self.bRArm:SetParent(self.mRArm,true)
self.bRHand:SetParent(self.mRHand,true)
self.bLShoul:SetParent(self.mLShoul,true)
self.bLArm:SetParent(self.mLArm,true)
self.bLHand:SetParent(self.mLHand,true)
--**Legs**
self.bRLeg:SetParent(self.mRLeg,true)
self.bRKnee:SetParent(self.mRKnee,true)
self.bLLeg:SetParent(self.mLLeg,true)
self.bLKnee:SetParent(self.mLKnee,true)
end
function this:Update()
if self.window:KeyHit(Key.R) then
if self.r == false then
self:SetPosition()
self:SetRotation()
self:CreateJoints()
self:SetParent()
self:SetMass(1.0)
self.r = true
end
end
if self.r == true then
self.player:SetPosition(self.bPelvis:GetPosition(true),true)
--self:UpdateBones()
end
if Window:GetCurrent():KeyHit(Key.E) then
self:SetMass(0)
self:DestroyJoints()
self.player:Release()
end
end
this:Start()
return ( this )
end