Jump to content

Ragdoll Beta | Engine Leadwerks Lua Script | Newton System.


Yue
 Share

Recommended Posts

This is something I have been working on that could aid the creation of these in the future:
https://github.com/Leadwerks/glTFExtensions

If these extensions are added to the Blender glTF exporter, the artist can set up colliders and joints in Blender and load them in Ultra ready to use.

  • Like 1
  • Upvote 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

3 hours ago, Josh said:

This is something I have been working on that could aid the creation of these in the future:
https://github.com/Leadwerks/glTFExtensions

If these extensions are added to the Blender glTF exporter, the artist can set up colliders and joints in Blender and load them in Ultra ready to use.

Thats like a valve mdl file, cool.

Link to comment
Share on other sites

 

Things I am learning the hard way. 

Joints do not collide between the rigid bodies that make it up. However, it only happens with the two pieces that make up that joint.

In my development process I have two joints coming out from the player's pelvis, one for the right leg and one for the left leg. Eventually the right leg (collision body) does not collide with the collision body of the pelvis. But if it is going to collide with the left leg, in the process of creating the joints these pieces collide with each other, two bodies cannot occupy the same space, and the dummy flies off like a pyre corn.

The solution to this is that the two legs, upper part, should have a debris type collider.

Translated with www.DeepL.com/Translator (free version)

 

 

 

image.thumb.png.27a8109e3321784d574eca22b346f23d.png
 

 

 

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

CSkeletal={
	
	Create = function(self,mesh)
		
		self.mesh = mesh
		
		local this={}
		setmetatable(this,self)
		self.__index = self

		function this:Init()
			self.mmo = "bone:"

			self:ScanBones()
			
			System:Print(">>>### OBJETO SKELETAL CREADO ###<<<")
		end

		function this:ScanBones()
			-- Trunk
			self.bHead   = self.mesh:FindChild(self.mmo .. "Head")
			self.bThorax = self.mesh:FindChild(self.mmo .. "Spine2")
			self.bSpine1 = self.mesh:FindChild(self.mmo .. "Spine1")
			self.bStomach= self.mesh:FindChild(self.mmo .. "Spine")

			-- Arms.
			self.bArmR   = self.mesh:FindChild(self.mmo .. "RightArm")
			self.bArmL   = self.mesh:FindChild(self.mmo .. "LeftArm")

			self.bElbowR = self.mesh:FindChild(self.mmo .. "RightForeArm")
			self.bElbowL = self.mesh:FindChild(self.mmo .. "LeftForceArm")

			self.bHandR  = self.mesh:FindChild(self.mmo .. "RightHand")
			self.bHandL  = self.mesh:FindChild(self.mmo .. "LeftHand")

			-- Legs.
			self.bLegR   = self.mesh:FindChild(self.mmo .. "RightUpLeg")
			self.bLegL   = self.mesh:FindChild(self.mmo .. "LeftUpLeg")

			self.bKneeR  = self.mesh:FindChild(self.mmo .. "RightLeg")
			self.bKneeL  = self.mesh:FindChild(self.mmo .. "LeftLeg")

			self.bFootR  = self.mesh:FindChild(self.mmo .. "RightFoot")
			self.bFootL  = self.mesh:FindChild(self.mmo .. "LeftFoot")
			

		end

		function this:GetPosBones()

			self.pHead   	= self.bHead:GetPosition(true)
			self.pThorax 	= self.bThorax:GetPosition(true)
			self.pStomach 	= self.bStomach:GetPosition(true)
			self.pLegR     	= self.bLegR:GetPosition(true)
			self.pLegL     	= self.bLegL:GetPosition(true)
			self.pKneeR		= self.bKneeR:GetPosition(true)
			self.pKneeL    	= self.bKneeL:GetPosition(true)
			self.pFootR    	= self.bFootR:GetPosition(true)
			self.pFootL		= self.bFootL:GetPosition(true)

		end

		function this:GetRotBones()

			self.rHead 		= self.bHead:GetRotation(true)
			self.rThorax    = self.bThorax:GetRotation(true)
			self.rStomach   = self.bStomach:GetRotation(true)
			self.rLegR      = self.bLegR:GetRotation(true)
			self.rLegL      = self.bLegL:GetRotation(true)
			self.rKneeR		= self.bLegR:GetRotation(true)
			self.rKneeL     = self.bKneeL:GetRotation(true)
			self.rFootR		= self.bFootR:GetRotation(true)
			self.rFootL		= self.bFootL:GetRotation(true)
		
		end 

		

		this:Init()
		return(this)
	end


}

This is the first step, I have repeated this so many times that I already feel comfortable writing scripts in Lua. 

At this point I love to simulate object oriented programming in Lua. I think it is the best programming out there. 

This class called skeleton is to scan the bones of the mesh and their respective rotation and location in 3d space.

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

import("Scripts/Game/Player/CSkeletal.lua")

CRagdoll={

	Create = function(self,mesh)

		self.mesh = mesh
		--self.mesh:SetRotation(0,90,0) -- Test.
		self.mat  = nil
		local this={}
		setmetatable(this,self)
		self.__index = self

		function this:Init()
			self.mesh = mesh
			self.mat = Material:Load("Materials/Effects/Invisible.mat")

			self.Skeletal = CSkeletal:Create(self.mesh)

			self:CreateMeshs()
			self:CreateShapes()
			self:SetRotation()
			self:CreateJoints()
			self:SetRotation()
			self:SetMass(10)
			
			System:Print(">>>### OBJETO RAGDOLL CREADO ###<<<")
		end

		function this:CreateJoints()
			self.Skeletal:GetPosBones()
			-- Trunk.
			self.jThoraxHead    = Joint:Hinge(self.Skeletal.pHead.x,self.Skeletal.pHead.y,self.Skeletal.pHead.z, 1,0,0, self.mThorax, self.mHead)
			self.jStomachThorax = Joint:Hinge(self.Skeletal.pSpine1.x,self.Skeletal.pSpine1.y,self.Skeletal.pSpine1.z,1,0,0,self.mStomach, self.mThorax )  
		end

		function this:CreateMeshs()
			-- Trunk.
			self.mHead   	= Model:Box()
			self.mThorax 	= Model:Box()
			self.mStomach	= Model:Box()
			-- Legs.
			self.mLegR  	= Model:Box()
			self.mLegL		= Model:Box()
			self.mKneeR     = Model:Box()
			self.mKneeL		= Model:Box()
			self.mFootR		= Model:Box()
			self.mFootL		= Model:Box()
			
			self:FixRotLegs()
			self:SetScale()
			self:SetMaterial()
			self:SetPosition()
		end
		
		function this:SetScale()
			-- Trunk.
			self.mHead:SetScale(0.32,0.32,0.32)
			self.mThorax:SetScale(0.3,0.23,0.2)
			self.mStomach:SetScale(0.25,0.15,0.25)
			-- Legs.
			self.mLegR:SetScale(0.15,0.25,0.25)
			self.mLegL:SetScale(0.15,0.25,0.25)
			self.mKneeR:SetScale(0.15,0.25,0.25)
			self.mKneeL:SetScale(0.15,0.25,0.25)
			self.mFootR:SetScale(0.15,0.25,0.25)
			self.mFootL:SetScale(0.15,0.25,0.25)
			
		end 
		
		function this:SetPosition()
			self.Skeletal:GetPosBones()
			-- Trunk.
			self.mHead:SetPosition(self.Skeletal.pHead,true)
			self.mThorax:SetPosition(self.Skeletal.pThorax,true)
			self.mStomach:SetPosition(self.Skeletal.pStomach,true)
			-- Legs.
			self.mLegR:SetPosition(self.Skeletal.pLegR,true)
			self.mLegL:SetPosition(self.Skeletal.pLegL,true)
			self.mKneeR:SetPosition(self.Skeletal.pKneeR,true)
			self.mKneeL:SetPosition(self.Skeletal.pKneeL,true)
			self.mFootR:SetPosition(self.Skeletal.pFootR,true)
			self.mFootL:SetPosition(self.Skeletal.pFootL,true)
			
		end

		function this:SetMaterial()
			self.mHead:SetMaterial(self.mat)
			self.mThorax:SetMaterial(self.mat)
			self.mStomach:SetMaterial(self.mat)

		end

		function this:SetRotation()

			self.Skeletal:GetRotBones()
			
			self.mHead:SetRotation(self.Skeletal.rHead,true)
			self.mThorax:SetRotation(self.Skeletal.rThorax,true)
			self.mStomach:SetRotation(self.Skeletal.rStomach,true)


		end

		function this:CreateShapes()

			self.shape = Shape:Sphere(0,0.5,-0.1)
			self.mHead:SetShape(self.shape)
			self.shape:Release()
			
			self.shape = Shape:Box(0,0.2,0)
			self.mThorax:SetShape(self.shape)
			self.shape:Release()

			self.shape = Shape:Box(0,0,-0.1)
			self.mStomach:SetShape(self.shape)
			self.shape:Release()


		end

		function this:SetMass(mass)
			-- Trunk.
			self.mHead:SetMass(0)
			self.mThorax:SetMass(mass)
			self.mStomach:SetMass(mass)
			-- Legs.
			self.mLegR:SetMass(mass)
			self.mLegL:SetMass(mass)
			self.mKneeR:SetMass(mass)
			self.mKneeL:SetMass(mass)
			self.mFootR:SetMass(mass)
			self.mFootL:SetMass(mass)
		end

		function this:FixRotLegs()
			self.Skeletal:GetRotBones()
			-- Legs.
			self.mLegR:SetRotation(self.Skeletal.rLegR,true)
			self.mLegL:SetRotation(self.Skeletal.rLegL,true)
			self.mKneeR:SetRotation(self.Skeletal.rKneeR,true)
			self.mKneeL:SetRotation(self.Skeletal.rKneeL,true)
			self.mFootR:SetRotation(self.Skeletal.rFootR,true)
			self.mFootL:SetRotation(self.Skeletal.rFootL,true)
		end


		function this:Update()
			self.Skeletal:GetRotBones()
			self.mesh:Turn(0,0.5,0)
			if Window:GetCurrent():KeyHit(Key.R) then
			
				self:SetRotation()
			end
		
		end
		

		this:Init()
		return(this)
	end


}

The ragdoll class, the interesting thing here is that when I press the R key, the joint adjusts according to where the character is facing, specifically the orientation of its bones.

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

7 hours ago, Thirsty Panther said:

Got to admire your perseverance Yue. You  have spent ages on this.

Glad it is finally working for you. 

Hi, your comment made me think that life is not at all easy for some people. I start with my weaknesses and that is that I don't speak English, learning programming has meant learning to brute force certain concepts. And I have gone around different types of engines and the problem is always the same, documentation in English, although they say I am very smart I am really stubborn, I don't know when to stop something that really doesn't work for me. The other thing is as my grandfather used to say, we are the result of circumstances in life and possibly if life were different I would be doing great things with computers.  But first there is food and shelter and family welfare, if this does not go well it would be impossible to sit down to create a work of art, or to study. Anyway, today I woke up philosophical. xD

Translated with www.DeepL.com/Translator (free version)

  • Like 1

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

Finish.

 

image.png.fe34f64dc28397f422cdb82809d5c51f.png

We have made it, I thank my dad my mom my wife my family, for the love and hate patience I have had for Josh and his Leadwerks engine. :D

 

But it doesn't end as long as we breathe and have internet.

The next challenge is for our character to stand up.  ( Josh's idea from a few months ago )

Whoever needs to implement this in their project, I receive money and do everything is difficult way through the underworld of Newtonian physics. 


image.png.56bbfe45fa7d7de2cec3920324e027dd.png

That's how I ended up. :D

 

image.thumb.png.425afdb2a9c6cf21ad25fd3d5b8b322f.png

  • Haha 2

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

 

 

The most complicated thing is to unite all the systems and make it work as expected, Ragdoll system + Animation system + Collisions + Character controller.  This looks very good to me, and I'm already thinking of a way to make the character stand up. 

What do you think?

  • Like 4

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...