Jump to content

[Continue Work ]Radgoll progress


Yue
 Share

Recommended Posts

Okay, so when your ragdoll is initialized, it appears the self.mHead, self.mStomach, etc. are all positioned and rotated at (0,0,0). I think. You need to set these to the starting position of the visual model, create joints, and then when the ragdoll is activated, position and rotate the ragdoll limbs to match the current orientation of the visual model.

Scripts.zip

Note the CreateJoints function is now using the position of the ragdoll limb, not the visual model.

I might have disabled collisions between ragdoll limbs at some point using SetCollisionType, so you should re-enable this if wanted.

Works perfectly, no changes to the engine are needed.

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Script.bodyHead = nil --Entity "Body Head"
Script.bodyFoot = nil --Entity "Body Foot"
Script.r = false
function Script:Start()
	
	self.boneHead = self.entity:FindChild("Bone1")
	self.boneFoot = self.entity:FindChild("Bone2")

	System:Print(self.boneHead)
	System:Print(self.boneFoot)
	
end


function Script:UpdateWorld()
	
	if self.r == false then 

		if Window:GetCurrent():KeyHit(Key.R) then 
			
			self:SetPosition()
			self:SetRotation()
			
				
		end 
	end

end


function Script:SetPosition()
	self.bodyHead:SetPosition(self.boneHead:GetPosition(true),true)
	self.bodyFoot:SetPosition(self.boneFoot:GetPosition(true),true)
end 

function Script:SetRotation()
	self.bodyHead:SetRotation(self.boneHead:GetRotation(true),true)
	self.bodyFoot:SetRotation(self.boneFoot:GetRotation(true),true)
end 

here I position the rigid bodies in the position and rotation of the bones.   This should be sufficient for when the model is pointed elsewhere. The next step is to create the single joint. 


Continue...
 

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites


Script.bodyHead = nil --Entity "Body Head"
Script.bodyFoot = nil --Entity "Body Foot"
Script.r = false
Script.joint = nil
function Script:Start()
	
	self.boneHead = self.entity:FindChild("Bone1")
	self.boneFoot = self.entity:FindChild("Bone2")

	System:Print(self.boneHead)
	System:Print(self.boneFoot)

	
	


end


function Script:UpdateWorld()
	
	if self.r == false then 

		if Window:GetCurrent():KeyHit(Key.R) then 
			
			self:SetPosition()
			self:SetRotation()
			

			self:CreateJoint()
			self:SetMass(1.0)
			self.entity:Hide()
		end 
	end

	--Rotate Player.
	if Window:GetCurrent():KeyDown(Key.A) then 
		System:Print("Rotate")
		self.entity:SetRotation(0,-90,0)
	end 
end

function Script:SetMass( mass )
	self.bodyHead:SetMass( mass)
	self.bodyFoot:SetMass(mass)
	
end 

function Script:CreateJoint()

	self.joint = Joint:Hinge(self.bodyHead:GetPosition(true).x, self.bodyHead:GetPosition(true).y, self.bodyHead:GetPosition(true).z, 1,0,0, self.bodyFoot, self.bodyHead) 
	self.joint:EnableLimits()
	self.joint:SetLimits(0,90)

end 


function Script:SetPosition()
	self.bodyHead:SetPosition(self.boneHead:GetPosition(true),true)
	self.bodyFoot:SetPosition(self.boneFoot:GetPosition(true),true)
end 

function Script:SetRotation()
	self.bodyHead:SetRotation(self.boneHead:GetRotation(true),true)
	self.bodyFoot:SetRotation(self.boneFoot:GetRotation(true),true)
end 

It's definitely not working, I don't know what the real problem is, I'm missing something I don't know what it is. 

I create the joint, but the hinge always runs in global mode, at least from my point of view, even if I rotate the monkey.

Scripts folder open.

Laboratorio.zip

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

Script.bodyHead = nil --Entity "Body Head"
Script.bodyFoot = nil --Entity "Body Foot"
Script.r = false
Script.joint = nil
function Script:Start()
	
	self.boneHead = self.entity:FindChild("Bone1")
	self.boneFoot = self.entity:FindChild("Bone2")

	System:Print(self.boneHead)
	System:Print(self.boneFoot)

end


function Script:UpdateWorld()
	
	if self.r == false then 

		if Window:GetCurrent():KeyHit(Key.R) then 
			if self.joint   then 
			self.joint:Release()
			end
			self:SetPosition()
			self:SetRotation()
			
			

			self:CreateJoint()
			self:SetMass(1.0)
			--self.entity:Hide()
		end 
	end

	--Rotate Player.
	if Window:GetCurrent():KeyHit(Key.G) then 
		System:Print("Rotate")
		self.entity:SetRotation(0,-90,0)
		
	end 

	if Window:GetCurrent():KeyDown(Key.Space) then

		self.bodyHead:AddForce(0,100,0)
		self.bodyFoot:AddForce(0,100,0)
	end
end

function Script:SetMass( mass )
	self.bodyHead:SetMass( mass)
	self.bodyFoot:SetMass(mass)

	self.bodyHead:SetVelocity(0,1,0)
	self.bodyFoot:SetVelocity(0,1,0)
	
end 

function Script:CreateJoint()

	self.joint = Joint:Hinge(self.bodyHead:GetPosition(true).x, self.bodyHead:GetPosition(true).y, self.bodyHead:GetPosition(true).z, 1,0,0, self.bodyFoot, self.bodyHead) 
	--self.joint:EnableLimits()
	--self.joint:SetLimits(0,90)

end 


function Script:SetPosition()
	self.bodyHead:SetPosition(self.boneHead:GetPosition(true),true)
	self.bodyFoot:SetPosition(self.boneFoot:GetPosition(true),true)
end 

function Script:SetRotation()
	self.bodyHead:SetRotation(self.boneHead:GetRotation(true),true)
	self.bodyFoot:SetRotation(self.boneFoot:GetRotation(true),true)
end 

I've turned this every which way, no matter what I do, the hinge revolves around the global coordinates, no matter what I turn the column that acts as a monicker for the ragdoll.

 

Update Scripts.

R key = activate ragdoll.
Space key = add force to the bodies.

G Key  = Turn Player. ( only one turn )

ERagdoll.lua

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

The code I posted works. Your joints need to be created when the ragdoll limbs are in the default pose. Then you position and rotate the ragdoll limbs to match the animated model, and your joints will rotate correctly.

  • Like 1
  • Thanks 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

15 hours ago, Josh said:

The code I posted works. Your joints need to be created when the ragdoll limbs are in the default pose. Then you position and rotate the ragdoll limbs to match the animated model, and your joints will rotate correctly.

image.thumb.png.aa94349647407572a9d93354ce033ebe.png

 

I think if I spoke English, I would be a genius.

I will give it a try. Hey and about SetPosition and SetRotation to recover the skeleton and animate it, any solution?

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

 

I can't figure this out, it obviously doesn't work for me.  Charrua makes this comment.

 

Each joint has a number of parameters controlling its geometry. An example is the position of the balland-
socket point for a ball-and-socket joint. The functions to set joint parameters all take global coordinates,
not body-relative coordinates. A consequence of this is that the rigid bodies that a joint connects must be
positioned correctly before the joint is attached.

 

That is, when I create the joint, for example the hinge joint, I find three parameters, which refer to the axis that is used. 

 

self.joint = Joint:Hinge(self.bodyHead:GetPosition(true).x, self.bodyHead:GetPosition(true).y, self.bodyHead:GetPosition(true).z, 1,0,0, self.bodyFoot, self.bodyHead) 

The parameter 1,0,0, refers to the fact that I use the X axis for the rotation of the hinge, but in my case and I don't know what happens, it stays with the global coordinate. 

Now, if I put 0,1,0, it is the same with the global coordinate in the Y axis.



 

Script.bodyHead = nil --Entity "Body Head"
Script.bodyFoot = nil --Entity "Body Foot"
Script.r = false
Script.joint = nil
function Script:Start()
	
	self.boneHead = self.entity:FindChild("Bone1")
	self.boneFoot = self.entity:FindChild("Bone2")

	self:SetPosition()
	self:SetRotation()


end


function Script:UpdateWorld()
	
	if self.r == false then 

		if Window:GetCurrent():KeyHit(Key.R) then 
			if self.joint   then 
			self.joint:Release()
			end
			self:SetPosition()
			self:SetRotation()
			
			

			self:CreateJoint()
			self:SetMass(1.0)
			--self.entity:Hide()
		end 
	end

	--Rotate Player.
	if Window:GetCurrent():KeyHit(Key.G) then 
		System:Print("Rotate")
		self.entity:SetRotation(0,-90,0)
		
	end 

	if Window:GetCurrent():KeyDown(Key.Space) then

		self.bodyHead:AddForce(0,100,0)
		self.bodyFoot:AddForce(0,100,0)
	end
end

function Script:SetMass( mass )
	self.bodyHead:SetMass( mass)
	self.bodyFoot:SetMass(mass)

	self.bodyHead:SetVelocity(0,1,0)
	self.bodyFoot:SetVelocity(0,1,0)
	
end 

function Script:CreateJoint()

	self.joint = Joint:Hinge(self.bodyHead:GetPosition(true).x, self.bodyHead:GetPosition(true).y, self.bodyHead:GetPosition(true).z, 1,0,0, self.bodyFoot, self.bodyHead) 
	--self.joint:EnableLimits()
	--self.joint:SetLimits(0,90)

end 


function Script:SetPosition()
	self.bodyHead:SetPosition(self.boneHead:GetPosition(true),true)
	self.bodyFoot:SetPosition(self.boneFoot:GetPosition(true),true)
end 

function Script:SetRotation()
	self.bodyHead:SetRotation(self.boneHead:GetRotation(true),true)
	self.bodyFoot:SetRotation(self.boneFoot:GetRotation(true),true)
end 

But this does not work, if someone wants to try the simple project, and help me to understand this, I appreciate it very much. It's just a simple articulation.

Mars.rar

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...