Jump to content

My character controller, progress.


Yue
 Share

Recommended Posts

--##################################################
--# Proytecto 	: Mars.
--# Scripter  	: Yue Rexie.
--# Sitio Web	: https://www.iris3dgames.xyz
--# Fichero		: CPlayer.lua
--##################################################
--# Notas		: Clase CPlayer para crear 
--#				  el objeto Jugador.
--##################################################

import("Scripts/Player/Classes/CRagDoll.lua")

CPlayer={}
	function CPlayer:New()

		local this={}
			
			this.world   = nil
			this.camera  = nil
			this.pPlayer = nil
			this.pCamera = nil
			this.player  = nil
			this.rotPP	 = Vec3()
			this.ragdoll = nil
			
			this.vel     = 0.0
			this.ang     = 180

			function this:Create()
				
				self.world  = World:GetCurrent()
				self.camera = self.world:FindEntity("Camera") 
				
				self.player = self.world:FindEntity("Yue")
				self.pPlayer= self.world:FindEntity("PivotPlayer")
				self.pCamera= self.world:FindEntity("PivotCamera")
				self.bNeck	= self.player:FindChild("mixamorig_Head")

				self.pPlayer:SetPosition(self.bNeck:GetPosition(true))
				--self.pPlayer:SetParent(self.bNeck,false)
				
				self.pCamera:SetPosition(self.pPlayer:GetPosition(true))
				self.pCamera:SetParent(self.pPlayer,true)
				self.pCamera:SetPosition(self.pPlayer:GetPosition(true).x, self.pPlayer:GetPosition(true).y-1, self.pPlayer:GetPosition(true).z-1, false ) 
				
			

				self.ragdoll  = CRagDoll:Create()
				
				--self.camera:SetDebugEntityBoxesMode(true)
				--self.camera:SetDebugPhysicsMode(true)

				System:Print("System Player create... OK!")
				
			end

			

			function this:Update()
					self.pPlayer:SetPosition(self.bNeck:GetPosition(true))
					self.camera:SetPosition(self.pCamera:GetPosition(true))
					self.camera:SetRotation(self.pCamera:GetRotation(true))
				
				self:Move()
				if self.ragdoll.r == true then 
					self.pPlayer:SetParent(nil,true)

				end 
				self:UpdateCamera()
				self.ragdoll:Update()
				
				

			end 


			function this:UpdateCamera()
				
				
				
				self.sx = Math:Round(Context:GetCurrent():GetWidth()/2)
				self.sy = Math:Round(Context:GetCurrent():GetHeight()/2)

				self.posMouse = Window:GetCurrent():GetMousePosition()
				Window:GetCurrent():SetMousePosition( self.sx, self.sy )
			
				self.dx = self.posMouse.x - self.sx 
				self.dy = self.posMouse.y - self.sy
							
				self.rot = self.pPlayer:GetRotation()
				
				
				if self.rot.x >= 45  then
					self.rot.x = 45
				elseif self.rot.x <= -45 then 
					self.rot.x = -45	
				end	
				
				self.rot.y = self.rot.y + self.dx /  50.0 / Time:GetSpeed() 
				self.rot.x = self.rot.x + self.dy /  50.0 / Time:GetSpeed() 
				
				self.pPlayer:SetRotation(self.rot, true )

			

			end

			function this:Move()
				self.vel = 0.0
				if Window:GetCurrent():KeyDown(Key.W) then 
					self.vel = 1.0
					if Window:GetCurrent():KeyDown(Key.Shift) then 
						self.vel = 2.0
					end
					self.ang = 180
				end

				if Window:GetCurrent():KeyDown(Key.S) then
					self.vel = 1.0
					self.ang = 0.0
				end

				self.player:SetInput(self.pCamera:GetRotation(true).y-self.ang,self.vel)

			end

			this:Create()
			

		return( this )
	end

 

  • Like 1

 

 

Link to comment
Share on other sites

Animations Walk, Idle. System Camera Orbit on player.

 

--##################################################
--# Proytecto 	: Mars.
--# Scripter  	: Yue Rexie.
--# Sitio Web	: https://www.iris3dgames.xyz
--# Fichero		: CPlayer.lua
--##################################################
--# Notas		: Clase CPlayer para crear 
--#				  el objeto Jugador.
--##################################################

import("Scripts/Player/Classes/CCamera.lua")
import("Scripts/Player/Classes/CAnimation.lua")
import("Scripts/Player/Classes/CRagDoll.lua")

CPlayer={}
	function CPlayer:New()

		local this={}
			
			this.world   = nil
			this.player  = nil
			this.ragdoll = nil
			this.anima   = nil
			self.anin	 = nil
			self.camera  = nil
			
			this.vel     = 0.0
			this.velAnim = 0.0
			this.ang     = 0.0
			this.jForce  = 0.0

			function this:Create()
				
				self.world = World:GetCurrent()
				self.player= self.world:FindEntity("Yue")
				
				self.camera= CCamera:New()
				self.camera:Update()

				self.anima    = CAnimation:Create()
				self.anim     = self.anima.idle
				self.velAnim  = 0.05
				self.player:PlayAnimation(self.anim,self.velAnim,0.1)
				
				self.ragdoll  = CRagDoll:Create()
				
				System:Print("System Player create... OK!")
				
			end

		
			function this:Update()

				self.camera:Update()
				self:Move()
				self.ragdoll:Update()	
			
			end 

		
			function this:Move()
				
				self.vel = 0.0
				self.anim = self.anima.idle
				if Window:GetCurrent():KeyDown(Key.W) then 
					self.anim = self.anima.walk
					self.ang = self.camera:GetRotationY()-180
					if Window:GetCurrent():MouseDown(2) then 
						self.ang = self.player:GetRotation(true).y
					end
					self.velAnim = 0.03
					self.vel = -1.0
					if Window:GetCurrent():KeyDown(Key.Shift) then 
						self.vel = -2.0
					end
				end
				if Window:GetCurrent():KeyDown(Key.S) then
					self.anim = self.anima.walk
					self.ang = self.camera:GetRotationY()
					if Window:GetCurrent():MouseDown(2) then 
						self.ang = self.player:GetRotation(true).y
					end
					self.vel = -1.0
					if Window:GetCurrent():KeyDown(Key.Shift) then 
						self.vel = -2.0
					end	
				end
				
				self:Jump()
				self.player:SetInput(self.ang,self.vel,0,self.jForce)
				
				self.player:PlayAnimation(self.anim,self.velAnim)
				
			end

			function this:Jump()
				self.jForce = 0
				if Window:GetCurrent():KeyHit(Key.Space) then 
					if self.player:GetAirborne()== false then 
						self.jForce = 10
					end
				end
			end

			this:Create()
			

		return( this )
	end

 

  • Like 1

 

 

Link to comment
Share on other sites

Looks great! You have the rare ability to write code and make animations.

Here is a challenge: You can make your character fall. Can you make them get back up again?

First, make two animations:

  • Lying on back and standing back up.
  • Lying on stomach and standing back up.

Now when the character falls, detect whether their torso is pointing up or down, and play the correct animation to make them stand back up. If you provide a suitable blend time value, it will smoothly reorient them from whatever position they are in.

  • 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

4 hours ago, Marcousik said:

Hey Yue how did you manage to change the shape by crouch/stand ?

I can't understand the question, the translator doesn't help me much. 

The crouching animation is maintained by pressing the C key.

 

 

 

Link to comment
Share on other sites

1 hour ago, Marcousik said:

Estaba preguntando sobre la colisión si escribes algo para cambiarlo, ya que puedes pasar por debajo de una caja cuando te agachas y no puedes si te paras.

self.c = 0
if Window:GetCurrent():KeyHit(Key.C) then
		self.c = 1 - self.c			
end 

if self.c == 1 then
		self.tc = true
else
		self.tc = false
end if 

self.player:SetInput(self.ang,self.vel,0,self.jForce, self.tc ) 

Un inconveniente por ahora es que al pasar por debajo de la apertura, si se presiona la tecla C de nuevo el personaje se pone de pie.
image.thumb.png.f445bf2d24f74e2df7fbc169cfdf0e54.png

 

La posible solución a esto es poner un cepillo invisible  en el pasillo, para que la tecla C, no active que el personaje se ponga de pie. Y el tipo de colisión pare este cepillo sería   trigger.

  • Like 1

 

 

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