Jump to content

Stupid Questions


Daemoc
 Share

Go to solution Solved by Daemoc,

Recommended Posts

Ok, stupid question time. There are going to be a lot of these stupid questions for a while. I can read and do math, but that’s where my knowledge of code ends.

1: First and foremost, should I make a new thread for each stupid question or should I just keep them all under the same topic?

2: Now for the first stupid question. I have a nice library of animations to drive a character mesh and it is only going to get bigger. A lot bigger. I thought I had the animation calls all worked out, but I ran into an issue last night. I have eight directional animations, (16 w/sprint, 32 w/pistol, 48 w/rifle, etc.), and I can only get the first 6 to work. Any animation call after the 6th just does not seem to work.

It is not the code itself as all of the calls work if they are in the first 6 operations, I think it has more to do with the lack of coding knowledge and relying on the different examples of code I have seen and replicated. The calls I am using are probably not meant to be used with so many variables.


Here is some example code with extreme shorthand, but the idea is there… (I am at work, I do not have access to the real code at the moment.)

if KeyDown(Key.W) then
	PlayAnimation(“^”,0.02,100,0)
end

if KeyDown(Key.W) and KeyDown(Key.D) then
	PlayAnimation(“^>”,0.02,100,0)
end

if KeyDown(Key.W) and KeyDown(Key.A) then
	PlayAnimation(“^<”,0.02,100,0)
end

if KeyDown(Key.D) then
	PlayAnimation(“>”,0.02,100,0)
end

if KeyDown(Key.A) then
	PlayAnimation(“<”,0.02,100,0)
end

if KeyDown(Key.S) then
	PlayAnimation(“v”,0.02,100,0)
end

if KeyDown(Key.S) and KeyDown(Key.D) then
	PlayAnimation(“v>”,0.02,100,0)
end

if KeyDown(Key.S) and KeyDown(Key.A) then
	PlayAnimation(“v<”,0.02,100,0)
end

This works, but for the first 6 operations. They all work on their own, and in the first 6, but after that it breaks. Also, This is just walk. I actually have the run animations in the code as well with "if shift run else walk" attached to each.

Those seem to work just as the above walks. But again, only the first 6. After that they break and refuse to play.

I know I am doing it wrong, I just don’t know how to do it right. Any tips would be appreciated. This is just the tip of the iceberg, I have plenty more questions inbound, but one thing at a time.

Link to comment
Share on other sites

I don't know Lua but it looks like you might sometimes trigger more than one PlayAnimation function per frame.  Meaning, if you hold down both the W and D keys, the first if statement will be true and it will trigger that PlayAnimation AND the next if statement will also be true and will trigger its respective PlayAnimation.  So I think you'd be blending two animations together. Look into using elseif statements.  Something like this (again, I don't know Lua but this seems like it could work):

if KeyDown(Key.W) and KeyDown(Key.D) then
  PlayAnimation(“^>”,0.02,100,0)
elseif KeyDown(Key.W) and KeyDown(Key.A) then
  PlayAnimation(“^<”,0.02,100,0)
elseif KeyDown(Key.W)
  PlayAnimation(“^”,0.02,100,0)
end

As for posting, if you have several questions at once, you probably want to use a single post for it.  If it's two or three that are unrelated topics, you may want to split them up.  But I'm not the Leadwerks police; that's just my preference.  Ideally you also search the forums first and you might find something that already covers your question and you can just continue the conversation in that thread.  That will help for anyone searching the forums for the same issue so they don't have to open 10 different threads to find their answer.

  • Thanks 1
Link to comment
Share on other sites

Here Perfect.

 

--################################################
--## Proyecto 	: 	Pawn.
--## Sitio Web 	: 	https://www.iris3dgames.xyz
--## Fichero 	: 	Player.lua
--## Scripter   : 	Yue Rexie.
--################################################
--## Notas		:   Fichero Clase Player.
--##			    Objetos Player son creados.
--################################################


Player={}

	function Player:New(pick,hud)
		
		
		local this={}
		this.pivotPlayer  	= nil
		this.pivotCamera    = nil
		this.cameraPlayer 	= nil
		this.player			= nil
		this.pos			= Vec3()

		this.vel			= 0
		this.rot            = 0

		this.pickInfo       = 0
		this.colGroundRay   = false
		
		this.forceJump      = 0

		-- Animations.
		this.idle			= "Idle"
		this.idleBox		= "IdleBox"
		this.walk			= "Walk"
		this.run			= "Run"
		this.walkBox		= "WalkBox"
		this.runBox			= "RunBox"
		this.jump			= "Jump"
		this.dead 			= "Dead"
		this.falling        = "Falling"
		this.fallingB		= "FallingBox"
		this.kick			= "Kick"
		this.energyOff		= "EnergyOff"
		
		this.animation 		= nil
		this.velAnim		= 0.03
		this.typeAnim		= 0
		this.blend 			= 100

		this.energyOut		= 0.001
		this.energyRun		= 0
		this.energyWalk		= 0

		this.soundWalk		= nil 
		this.channelWalk	= nil
		this.pitch 			= nil 

		this.soundWind		= nil 
		this.channelWind	= nil

		this.soundMusic		= nil
		this.channelMusic   = nil
	


		function this:StartCameraOrbit(player,pivotPlayer, pivotCamera, cameraPlayer)
			
			self.player   	  = player
			self.pivotPlayer  = pivotPlayer
			self.pivotCamera  = pivotCamera
			self.cameraPlayer = cameraPlayer
			
			self.pivotCamera:SetParent(self.pivotPlayer,true)
			
		
			self.cameraPlayer:SetRange(0.01,1000)
			
			self.player:SetPickMode(0)
		
		

			self:InitSoundWalk()
			--self:InitSoundAmbient()
	
			
		end

		function this:InitSoundAmbient()
			self.soundWind = Sound:Load("Sound/Ambient/Viento.wav")
			self.channelWind = Source:Create()
			self.channelWind:SetSound(self.soundWind)
			self.soundWind:Release()
			self.channelWind:SetVolume(0.2) 
			self.channelWind:SetLoopMode(true)
			self.channelWind:Play()


			self.soundMusic = Sound:Load("Sound/Ambient/airtone_nightRain.wav")
			self.channelMusic = Source:Create()
			self.channelMusic:SetSound(self.soundMusic)
			self.soundMusic:Release()
			self.channelMusic:SetVolume(0.3) 
			self.channelMusic:SetLoopMode(true)
			self.channelMusic:Play()

		end

		function this:InitSoundWalk()

			self.soundWalk = Sound:Load("Sound/Player/footstep.wav")
			self.channelWalk = Source:Create() 
			self.channelWalk:SetSound(self.soundWalk) 
			self.soundWalk:Release() 

			self.channelWalk:SetLoopMode(true) 
			self.channelWalk:SetVolume(1) 
			self.channelWalk:Play()
			self.channelWalk:Pause()
			self.pitch = self.channelWalk:GetPitch()

		end

		function this:Update()
			
			self:UpdateCameraOrbit()
			self:UpdateMovent()
			self:Jump()
			self:ColRayCamera()
			self:Animations()
			
		end

		function this:UpdateSounds()
			
			if self.colGroundRay == true then 
				if Window:GetCurrent():KeyHit(Key.Shift) then 
					self.channelWalk:SetPitch(self.channelWalk:GetPitch()*2)
				
				end

				if Window:GetCurrent():KeyDown(Key.Shift) == false then 
					self.channelWalk:SetPitch(self.pitch)
				end


				if Window:GetCurrent():KeyHit(Key.W) or Window:GetCurrent():KeyHit(Key.S) then 
					
						self.channelWalk:Resume()
				
				end
				
				if Window:GetCurrent():KeyDown(Key.W)==false  and Window:GetCurrent():KeyDown(Key.S)==false then 
					self.channelWalk:Pause()
				else 

					self.channelWalk:Resume()
				end
			
				

			
	
			end
			
		end


		function this:UpdateCameraOrbit()
		
			
			if menuVisible == 1 then
				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.rotacion = self.pivotPlayer:GetRotation()
				
				
				if self.rotacion.x >= 60  then
					self.rotacion.x = 60
				elseif self.rotacion.x <= -45 then 
					self.rotacion.x = -45	
				end	
				
				self.rotacion.y = self.rotacion.y + self.dx /  50.0 / Time:GetSpeed() 
				self.rotacion.x = self.rotacion.x + self.dy /  50.0 / Time:GetSpeed() 
				
				--## Rotate Pivot Player.
	
					self.pivotPlayer:SetRotation(self.rotacion, true )
				
			end

		end

		--## Movent Player.
		function this:UpdateMovent()
		
			self:UpdatePosPivotPlayer()
		
		
			self.velAnim = 0.03
			hud.energy = self.energyOut
			self.energyOut = 0.001
			
				if Window:GetCurrent():KeyDown(Key.W) then
					self.energyOut = self.energyWalk
					self:RunPlayer()
					if hud.posEnergy < 180.0 then
						self.rot = self.pivotPlayer:GetRotation(false).y
					end
				elseif Window:GetCurrent():KeyDown(Key.S) then
					self.energyOut = self.energyWalk
					self:RunPlayer()
					if hud.posEnergy < 180.0 then
						self.rot = self.pivotPlayer:GetRotation(false).y -180
					end
				else 
					self.vel = 0
				end
		

			if Window:GetCurrent():KeyDown(Key.W) or Window:GetCurrent():KeyDown(Key.S) then
			
				if pick.itemBox == false then 
					self.animation = self.walk
				else 
					
					self.animation = self.walkBox
				end 

				if Window:GetCurrent():KeyDown(Key.Shift) then
					if pick.itemBox == true then 
						self.animation = self.runBox
					else
						self.animation = self.run
					end
				end
			else 
				if pick.itemBox == false then 
					self.animation = self.idle
				else
					self.animation = self.idleBox
					
				end
			end

			if Window:GetCurrent():KeyDown(Key.E) then 
				--if pick.itemBox == false then 
					self.typeAnim = 0
					self.animation = self.kick
				--end
			end

			if hud.posEnergy < 180 then else 
				self.vel = 0
				

			end


			self.player:SetInput(self.rot,self.vel, 0, self.forceJump,false, 1.0, 0.5, true, 0)
			
		end

		
	

		function this:UpdatePosPivotPlayer()
			
			self.pivotPlayer:SetPosition(self.player:GetPosition().x,self.player:GetPosition().y+1.7,self.player:GetPosition().z)
		
		end
	
		function this:RunPlayer()
				self.velAnim = 0.03
				self.vel = 1.5
				if Window:GetCurrent():KeyDown(Key.Shift) then
					self.vel = 3.5
					self.energyOut = self.energyRun
					self.velAnim = 0.05
					
				end
		end

		function this:Jump()
					
			self.forceJump = 0.0
			if self:GetColRay() == true then
					--System:Print(self.pickInfo.position)
					self.pos = self.pickInfo.position
					self.typeAnim = 0
					
					self:UpdateSounds()
					--self.animation = self.idle	
			else 
					self.typeAnim = 1
					if pick.itemBox == false then 
						self.animation = self.falling
					else
						self.animation = self.fallingB
					end
					
					self.channelWalk:Pause()
					
					
					if self.player:GetPosition().y  < self.pos.y - 25 then
						self.player:SetPosition(self.pos.x,self.pos.y+5,self.pos.z)
					end
					
				
			end

			--self.typeAnim = 0
			
			--## Jump.
			if Window:GetCurrent():KeyHit(Key.Space) == true then 
				
                if self:GetColRay() == true then
					self.animation = self.jump
					self.typeAnim = 1
					self.velAnim = 0.5
					
					--self.forceJump = 7.0
					
				end
			end	
					
		end


		function this:GetColRay()
			
			self.pickInfo = PickInfo()

			self.colGroundRay =  World:GetCurrent():Pick(Vec3(self.player:GetPosition(true).x, self.player:GetPosition(true).y+0.1, self.player:GetPosition(true).z), Vec3(self.player:GetPosition(true).x, self.player:GetPosition(true).y-0.5, self.player:GetPosition(true).z),self.pickInfo, 0.001 )
			
			--self.posBone1 = self.player:FindChild("Rayo"):GetPosition(true)
			--self.colGroundRay = World:GetCurrent():Pick(self.posBone1.x,self.posBone1.y+0.2,self.posBone1.z, self.posBone1.x,self.posBone1.y-0.2, self.posBone1.z, self.pickInfo,0,true,0)
			--System:Print(self.player:GetCollisionType())
			return self.colGroundRay
		end

		function this:ColRayCamera()

			self.posPivotPlayer = self.pivotPlayer:GetPosition(true)
			self.posPivotCamera = self.pivotCamera:GetPosition(true)
			
			self.pickInfoRayCamera = PickInfo()
			self.GetColRayCamera = World:GetCurrent():Pick( self.posPivotPlayer, self.posPivotCamera,self.pickInfoRayCamera,0,true )
			
			self.cameraPlayer:SetRotation(self.pivotCamera:GetRotation(true))
			if self.GetColRayCamera  then
				
					self.cameraPlayer:SetPosition(self.pickInfoRayCamera.position.x+(self.pickInfoRayCamera.normal.x/12),self.pickInfoRayCamera.position.y+(self.pickInfoRayCamera.normal.y/12.0),self.pickInfoRayCamera.position.z+(self.pickInfoRayCamera.normal.z/12.0),false)
					
				
			else
			
				self.cameraPlayer:SetRotation(self.pivotPlayer:GetRotation(true))
				self.cameraPlayer:SetPosition(self.pivotCamera:GetPosition(true))
				
			end
			


		end 

		--## Animation Player.
		function this:Animations()

		if hud.posEnergy < 180.0 then
			
		else
			self.animation = self.dead
		end

			self.player:PlayAnimation(self.animation, self.velAnim,self.blend,self.typeAnim )
			
		end

		return this

	end

 

  • Thanks 1

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

@gamecreator

That almost did it, here is what I have now...

	--Idle
	if self.entity:GetAirborne()==false then
		newmode = "idle"
		self.entity:PlayAnimation("idle_civ",0.05)
		self.entity:Stop()
	end

	--Jump
	if self.entity:GetAirborne()==false and window:KeyDown(Key.Space) then
		newmode = "jump"
		self.entity:PlayAnimation("jump_civ",0.01,0,1)
	end

	--Falling
	if self.entity:GetAirborne()==true then
		newmode = "drop"
		self.entity:PlayAnimation("drop_civ",0.05)
		self.entity:Stop()
	end

	--Forward Motion
	if self.entity:GetAirborne()==false and window:KeyDown(Key.W) then
		if window:KeyDown(Key.Shift) and window:KeyDown(Key.D) then
		newmode = "fr_run"
		self.entity:PlayAnimation("fr_jog_civ",0.03,100)
		elseif
		window:KeyDown(Key.Shift) and window:KeyDown(Key.A) then
		newmode = "fl_run"
		self.entity:PlayAnimation("fl_jog_civ",0.03,100)
		elseif
		window:KeyDown(Key.Shift) then
		newmode = "f_run"
		self.entity:PlayAnimation("f_jog_civ",0.03,100)
		elseif
		window:KeyDown(Key.D) then
		newmode = "fr_walk"
		self.entity:PlayAnimation("fr_walk_civ",0.02,100)
		elseif
		window:KeyDown(Key.A) then
		newmode = "fl_walk"
		self.entity:PlayAnimation("fl_walk_civ",0.02,100)
		else
		newmode = "f_walk"
		self.entity:PlayAnimation("f_walk_civ",0.02,100)
		end
	end

	--Rearward Motion
	if self.entity:GetAirborne()==false and window:KeyDown(Key.S) then
		if window:KeyDown(Key.Shift) and window:KeyDown(Key.D) then
		newmode = "rr_run"
		self.entity:PlayAnimation("rr_jog_civ",0.03,100)
		elseif
		window:KeyDown(Key.Shift) and window:KeyDown(Key.A) then
		newmode = "rl_run"
		self.entity:PlayAnimation("rl_jog_civ",0.03,100)
		elseif
		window:KeyDown(Key.Shift) then
		newmode = "r_run"
		self.entity:PlayAnimation("r_jog_civ",0.03,100)
		elseif
		window:KeyDown(Key.D) then
		newmode = "rr_walk"
		self.entity:PlayAnimation("rr_walk_civ",0.02,100)
		elseif
		window:KeyDown(Key.A) then
		newmode = "rl_walk"
		self.entity:PlayAnimation("rl_walk_civ",0.02,100)
		else
		newmode = "r_walk"
		self.entity:PlayAnimation("r_walk_civ",0.02,100)
		end
	end

	--Rightward Motion
	if self.entity:GetAirborne()==false and window:KeyDown(Key.D) then
		if window:KeyDown(Key.Shift) then
		newmode = "sr_run"
		self.entity:PlayAnimation("sr_jog_civ",0.03,100)
		else
		newmode = "sr_walk"
		self.entity:PlayAnimation("sr_walk_civ",0.02,100)
		end
	end

	--Leftward Motion
	if self.entity:GetAirborne()==false and window:KeyDown(Key.A) then
		if window:KeyDown(Key.Shift) then
		newmode = "sl_run"
		self.entity:PlayAnimation("sl_jog_civ",0.03,100)
		else
		newmode = "sl_walk"
		self.entity:PlayAnimation("sl_walk_civ",0.02,100)
		end
	end

Although I have a blending conflict issues. The < and > animations are blending with the <^, ^>, >V, V< animations and causing oddities. It is all working though. Now that I see how the <, <^ and ^ are blending I might be able to omit the <^ animation altogether. I just would rather have final say over the animation look rather than relying on the blending model.

Any ideas how I can isolate those commands?

 

@Iris3D Games

Thanks bud! ?

That looks like you have a lot there. I am definitely going to study the code and what you are doing there. I don't really know enough to full understand everything yet, but once I get a better grasp of the language I am sure I will be able to wrap my head around that example.

  • Like 1
Link to comment
Share on other sites

I'm always learning something, and thanks to your input, I saw the GetAirborne command, really my system lacks that command, and no more at first glance I think it serves to detect the character if it goes down.  This is crazy. :D

  • Like 1

Mars.jpg.89ab63a64eebc1f5ada0ab82b66a1f8c.jpg

 

 

Link to comment
Share on other sites

@Iris3D Games

Aye, I do not think I will ever wrap my head around enough code to make a game. There is so much to soak in it would take years. I am having fun with it though. I hope to learn enough to play/test my art assets in game, but I have no illusions of creating an entire game from scratch. You never know though.

I did a test changing the <^, ^> animations to ^ and it did in fact blend quite nice. Usable at least. The down side is the <V, V> are completely opposite of <, > so I can not rely on the blending. I will have to find another way to separate and dictate those functions.

Link to comment
Share on other sites

  • Solution

I Got it!

I had to change the side motions

	--Rightward Motion
	if self.entity:GetAirborne()==false and (window:KeyDown(Key.W) or window:KeyDown(Key.S))== false then
		if window:KeyDown(Key.Shift) and (window:KeyDown(Key.D) then
		newmode = "sr_run"
		self.entity:PlayAnimation("sr_jog_civ",0.03,100)
		elseif
		(window:KeyDown(Key.D)
		newmode = "sr_walk"
		self.entity:PlayAnimation("sr_walk_civ",0.02,100)
		else
		end
	end

	--Leftward Motion
	if self.entity:GetAirborne()==false and (window:KeyDown(Key.W) or window:KeyDown(Key.S))== false then
		if window:KeyDown(Key.Shift) and (window:KeyDown(Key.A) then
		newmode = "sl_run"
		self.entity:PlayAnimation("sl_jog_civ",0.03,100)
		elseif
		(window:KeyDown(Key.A)
		newmode = "sl_walk"
		self.entity:PlayAnimation("sl_walk_civ",0.02,100)
		else
		end
	end

I don't know if this is the right way to do it. Heck, it might cause blue screens after 15 mins, but it works.

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