Jump to content

debug char. script please.


VicToMeyeZR
 Share

Recommended Posts

New update :unsure:

 

require("scripts/class")
require("scripts/XML/XML")

local class=CreateClass(...)
local path = string.lower(StripExt(class.modelreference.path))

local obj,err = XmlParser:ParseXmlFile(path..".xml")


function class:InitDialog(grid)
self.super:InitDialog(grid)
group = grid:AddGroup("Animations")
if (not err) then
	for i,xmlNode in pairs(obj.ChildNodes) do
		if(xmlNode.Name=="start") then
			for i,subXmlNode in pairs(xmlNode.ChildNodes) do
				if(subXmlNode.Name) then
					group:AddProperty(subXmlNode.Name.."_start", PROPERTY_INTEGER, "", ""..subXmlNode.Attributes.value.."")
				end
			end
		end
	end
	for i,xmlNode in pairs(obj.ChildNodes) do
		if(xmlNode.Name=="end") then
			for i,subXmlNode in pairs(xmlNode.ChildNodes) do
				if(subXmlNode.Name) then
					group:AddProperty(subXmlNode.Name.."_end", PROPERTY_INTEGER, "", ""..subXmlNode.Attributes.value.."")
				end
			end
		end
	end
end
group:Expand(1)
end

function class:CreateObject(model)

local object = self.super:CreateObject(model)

object.model = model

local pos = object.model:GetPosition()
object.model:SetPosition(Vec3(pos.x, pos.y, pos.z))

object.framestart = 0
object.frameend = 50

object.height = tonumber(object:GetKey("controller_height", "1.8"))
local radius = tonumber(object:GetKey("controller_radius", "0.4"))
local step = tonumber(object:GetKey("controller_step_height", "0.5"))
local slope = tonumber(object:GetKey("controller_max_slope", "45.0"))

object.rotation = 0
object.forward = 0
object.reverse = 0
object.sright = 0
object.sleft = 0
object.tleft = 0
object.tright = 0
object.jump = 0
object.moveSpeed = 2
object.strafeSpeed = 2

--Notify(object.framestart)  // Debug

function object:SetKey(key,value)
	if key=="idle_start" then
		self.idle_start = tonumber(value)
	elseif key=="idle_end" then
		self.idle_end = tonumber(value)
	elseif key=="walk_start" then
		self.walk_start = tonumber(value)
	elseif key=="walk_end" then
		self.walk_end = tonumber(value)
	elseif key=="run_start" then
		self.run_start = tonumber(value)
	elseif key=="run_end" then
		self.run_end = tonumber(value)
	elseif key=="jump_start" then
		self.jump_start = tonumber(value)
	elseif key=="jump_end" then
		self.jump_end = tonumber(value)
	elseif key=="crouch_start" then
		self.crouch_start = tonumber(value)
	elseif key=="crouch_end" then
		self.crouch_end = tonumber(value)
	elseif key=="strafeleft_start" then
		self.strafeleft_start = tonumber(value)
	elseif key=="strafeleft_end" then
		self.strafeleft_end = tonumber(value)
	elseif key=="straferight_start" then
		self.straferight_start = tonumber(value)
	elseif key=="straferight_end" then
		self.straferight_end = tonumber(value)
	elseif key=="height" then
		self.height = tonumber(vaue)
	else 
		return self.super:SetKey(key,value)

	end
	return 1
end

function object:GetKey(key,value)
	if key=="idle_start" then
		return self.idle_start
	elseif key=="idle_end" then
		return self.idle_end
	elseif key=="walk_start" then
		return self.walk_start
	elseif key=="walk_end" then
		return self.walk_end
	elseif key=="run_start" then
		return self.run_start
	elseif key=="run_end" then
		return self.run_end
	elseif key=="jump_start" then
		return self.jump_start
	elseif key=="jump_end" then
		return self.jump_end
	elseif key=="crouch_start" then
		return self.crouch_start
	elseif key=="crouch_end" then
		return self.crouch_end
	elseif key=="strafeleft_start" then
		return self.strafeleft_start
	elseif key=="strafeleft_end" then
		return self.strafeleft_end
	elseif key=="straferight_start" then
		return self.straferight_start
	elseif key=="straferight_end" then
		return self.straferight_end
	elseif key=="height" then
		return self.height
	else
		return self.key
	end 
	return value
end

       function object:StartAnimations(movement)
               object.framestart = object:GetKey(movement .. "_start", "")
               return object.framestart
       end

       function object:EndAnimations(movement)
               object.frameend = object:GetKey(movement .. "_end")
               return object.frameend
       end

function object:LockKeys(model)

	self.super:LockKeys()
end

function object:UnlockKeys(model)

	self.super:UnlockKeys()
end

function object:UpdateMatrix()

end

function object:Reset()

end

function object:SetTarget(target,index)

end

function object:Collision(entity,position,normal,force,speed)

end

function object:ReceiveMessage(message,extra)
	if message=="forward" then
		object.forward = tonumber(extra) * object.moveSpeed
	elseif message=="reverse" then
		object.reverse = tonumber(extra) * object.moveSpeed
	elseif message=="stop" then
		object.forward = tonumber(extra) * object.moveSpeed
		object.reverse = tonumber(extra) * object.moveSpeed
	elseif message=="sleft" then
	elseif message=="sright" then
	elseif message=="tleft" then
	elseif message=="tright" then
	elseif message=="crouch" then
	elseif message=="jump" then
	elseif message=="attack" then
	else
		self.super:ReceiveMessage(message,extra)
	end
end

function object:Render()

	object.framestart = object:StartAnimations("idle")
	object.frameend = object:EndAnimations("idle")
	object.move = 0
	if GetGlobalString("mode") == "GAME_MODE" then
		local pos = object.model:GetPosition()
		if object.forward > 1 then	
			object.model:SetPosition(Vec3(pos.x, pos.y, pos.z+object.forward))
		elseif object.reverse < -1 then
			object.model:SetPosition(Vec3(pos.x, pos.y, pos.z+object.reverse))
		else
			object.frame = math.fmod(AppTime()/30, object.framestart - object.frameend) + object.framestart
			Animate(object.model, object.frame, 0.5, 0, true)
		end

	else

	end

	if GetGlobalString("mode") ~= "GAME_MODE" then
		if object.frameend ~= nil and object.frameend ~= 0 or object.framestart ~= nil then
			object.frame = math.fmod(AppTime()/30, object.framestart - object.frameend) + object.framestart
			Animate(object.model, object.frame, 0.5, 0, true)
		end
	end

end

function object:Free(model)

	self.super:Free()
end

end
--[[
function class:Free()

self.super:Free()
end
]]--

 

and the keyboard controller

 

require("scripts/class")
require("Scripts/Constants/keycodes")
require("Scripts/hooks")


local class=CreateClass(...)


-- we can get the value by passing the string to _G[]
function class:InitDialog(grid)
self.super:InitDialog(grid)
group = grid:AddGroup("Movement Controls")

letters = "NO_KEY,KEY_BACKSPACE,KEY_TAB,KEY_CLEAR,KEY_RETURN,KEY_ENTER,KEY_ESCAPE,KEY_SPACE,KEY_PAGEUP,KEY_PAGEDOWN,KEY_END,KEY_HOME,KEY_LEFT,KEY_RIGHT,KEY_UP,KEY_DOWN,KEY_SELECT,KEY_PRINT,KEY_EXECUTE,KEY_SCREEN,KEY_INSERT,KEY_DELETE,KEY_0,KEY_1,KEY_2,KEY_3,KEY_4,KEY_5,KEY_6,KEY_7,KEY_8,KEY_9,KEY_NUM0,KEY_NUM1,KEY_NUM2,KEY_NUM3,KEY_NUM4,KEY_NUM5,KEY_NUM6,KEY_NUM7,KEY_NUM8,KEY_NUM9,KEY_NUMMULTIPLY,KEY_NUMADD,KEY_NUMSUBSTRACT,KEY_NUMDECIMAL,KEY_NUMDIVIDE,KEY_F1,KEY_F2,KEY_F3,KEY_F4,KEY_F5,KEY_F6,KEY_F7,KEY_F8,KEY_F9,KEY_F10,KEY_F11,KEY_F12,KEY_TILDE,KEY_MINUS,KEY_EQUALS,KEY_OPENBRACKET,KEY_CLOSEDBACKET,KEY_BACKSLASH,KEY_SEMICOLON,KEY_QUOTES,KEY_COMMA,KEY_PERIOD,KEY_SLASH,KEY_LSHIFT,KEY_RSHIFT,KEY_LCONTROL,KEY_RCONTROL,KEY_LALT,KEY_RALT,KEY_LSYS,KEY_RSYS"
       for i = 65,90 do
               letters = letters..",".."KEY_"..string.char(i)
       end
       group:AddProperty("forward", PROPERTY_CHOICEEDIT, letters, "Forward")
group:AddProperty("backward", PROPERTY_CHOICEEDIT, letters, "Backward")
group:AddProperty("strafe_left", PROPERTY_CHOICEEDIT, letters, "Strafe Left")
group:AddProperty("strafe_right", PROPERTY_CHOICEEDIT, letters, "Strafe Right")
group:AddProperty("rotate_right", PROPERTY_CHOICEEDIT, letters, "Rotate Left")
group:AddProperty("rotate_right", PROPERTY_CHOICEEDIT, letters, "Rotate Right")
group:AddProperty("jump", PROPERTY_CHOICEEDIT, letters, "Jump")
group:AddProperty("duck", PROPERTY_CHOICEEDIT, letters, "Duck")

group:Expand(1)
end

function class:CreateObject(model)
local object=self.super:CreateObject(model)

object.model = model
object.forward = ""
object.backward = ""
object.strafeLeft = ""
object.strafeRight = ""
object.rotateLeft = ""
object.rotateRight = ""
object.jump = ""
object.duck = ""
object.speed = 2
object.moveOneTime = false
object.strafeOneTime = false


function object:SetKey(key,value)
	if key == "forward" then
		object.forward = value
	elseif key == "backward" then
		object.backward = value
	elseif key == "strafe_left" then
		object.strafeLeft = value
	elseif key == "strafe_right" then
		object.strafeRight = value
	elseif key == "rotate_left" then
		object.rotateLeft = value
	elseif key == "rotate_right" then
		object.rotateRight = value
	elseif key == "jump" then
		object.jump = value
	elseif key == "duck" then
		object.duck = value
	else
		return self.super:SetKey(key,value)
	end
	return 1
end

function object:GetKey(key,value)
	if key == "forward" then
		return object.forward
	elseif key == "backward" then
		return object.backward
	elseif key == "strafe_left" then
		return object.strafeLeft
	elseif key == "strafe_right" then
		return object.strafeRight
	elseif key == "rotate_left" then
		return object.rotateLeft
	elseif key == "rotate_right" then
		return object.rotateRight
	elseif key == "jump" then
		return object.jump
	elseif key == "duck" then
		return object.duck
	else
		return self.super:GetKey(key,value)
	end
	return value
end

function object:Update()
	t = model:GetTarget(0)

	if GetGlobalString("mode") == "GAME_MODE" then
		if t ~= nil then
			if KeyHit(_G[object.forward]) == 1 then
				object.moveOneTime = true
				t:SendMessage("forward", "1")

			elseif KeyHit(_G[object.backward]) == 1 then
				object.moveOneTime = true
				t:SendMessage("reverse", "-1")
			else
				if KeyDown(_G[object.forward]) == 0 and KeyDown(_G[object.backward]) == 0 and object.moveOneTime == true then
					-- we only want to send the stop message once
					object.moveOneTime = false
					t:SendMessage("stop","0")
				end
			end

			if KeyHit(_G[object.strafeLeft]) == 1 then
				object.strafeOneTime = true
				t:SendMessage("strafe", "0", "-1")
			elseif KeyHit(_G[object.strafeRight]) == 1 then
				object.strafeOneTime = true
				t:SendMessage("strafe", "0", "1")
			else
				if KeyDown(_G[object.strafeLeft]) == 0 and KeyDown(_G[object.strafeRight]) == 0 and object.strafeOneTime == true then
					-- we only want to send the stop message once
					object.strafeOneTime = false
					t:SendMessage("strafe", "0", "0")
				end
			end

			if KeyHit(_G[object.jump]) == 1 then
				t:SendMessage("jump", "0", "4")
			end
		end
	else
	end
end

function object:UpdateMatrix()

end

--[[
function object:LockKeys(model)

	self.super:LockKeys()
end
]]--

--[[
function object:UnlockKeys(model)

	self.super:UnlockKeys()
end
]]--

--[[
function object:UpdateMatrix()

end
]]--

--[[
function object:Reset()

end
]]--

--[[
function object:SetTarget(target,index)

end
]]--

--[[
function object:Collision(entity,position,normasl,force,speed)

end
]]--
--[[
function object:ReceiveMessage(message,extra)
	if message="" then

	else
		self.super:ReceiveMessage(message,extra)
	end
end
]]--


function object:Free(model)
	--Notify("Inside free")
	self.super:Free()
end

end

--[[
function class:Free()

self.super:Free()
end
]]--

 

THis is a modification to Ricks...

 

My question so far. How to determine movement speed based on the sise of the virtual world? Should I use a mathematical calculation based on the height of the model?

 

If I move forward 3 in the editor how much is that in reference to real world terms?

AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD

76561197984667096.png

Link to comment
Share on other sites

My question so far. How to determine movement speed based on the sise of the virtual world? Should I use a mathematical calculation based on the height of the model?

 

I think you should put a setting in the character thingoid for speed. Let the users determine what they want to use per character instance. I didn't do that because I was lazy, but it's the ideal situation.

Link to comment
Share on other sites

Yeah. Initially I wanted to update and use the character thingoid, but I couldn't get the animations to play correctly based on the character thingoid...

 

 

"when you send the message to the character thingoid, I couldn't find the right was to access that message in the character animation sequences. I was trying to reference the object.move for my if elseif, but that didn't come out right. Accessing those direct messages would be better"

 

 

Also, what I meant on speed. Right now when I move forward 3 my toon moves ~REALLY fast.. But thats the same speed setting you used, so I can't quite figure out why.

 

Also, my character mesh doesn't interact with the terrain mesh, it always at plain 0 on y..

 

I didn't see where you did that in the character thingoid, but your controller does go with the terrain mesh.

AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD

76561197984667096.png

Link to comment
Share on other sites

Also, my character mesh doesn't interact with the terrain mesh, it always at plain 0 on y..

 

When in game mode you have to position your character mesh to where the controller is. The issue is if you just use the position of the controller it'll place your mesh in the middle Y wise of the controller. So you need to subtract 1/2 the height of the controller for the Y axis and use that.

 

self.characterModel:SetPosition(Vec3(object.controller.position.x, object.controller.position.y - (object.height/2) , object.controller.position.z))

 

I think the problem you have here is that you aren't creating a controller. You would want to use the controller otherwise you would need to make your own controller to get physics working and that's a decent size task.

Link to comment
Share on other sites

That part I don't understand. The model has physics. Should they NOT interact with the terrain mesh, as all the physics should?

 

 

The model does have physics but you are calling object.model:SetPosition on it. Calling SetPosition(), MoveEntity(), RotateEntity(), or TurnEntity() all turn the physics off for physics bodies. This is why controllers were created. Without the controller you have to call the physics methods to get a physics body to move and get physics working, and that's not the easiest to get going. This is why Josh created the controller object. He did all that coding already for us in a controller that fits most needs.

 

Basically it means all your characters should have a controller around them. The controller is what you move around with UpdateController() and you make the model just follow the controller. Your actual character mesh then pretty much becomes a dummy object. Think of your character mesh there for the visual aspect and your controller there for the physics aspect. You move the controller around and make the mesh following it. You would animate the mesh though. The controller is just pure physics so you don't animate that.

Link to comment
Share on other sites

  • 2 weeks later...

I think it's easier to use separate files for each animation sequence, but this is useful if they are merged into one.

 

You can get a significant savings in speed by only animating entities in the object:Render() function. That way if they aren't rendered, they won't be animated.

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

That is where I put my animation...

 

I used my own function

       function object:StartAnimations(movement)
               object.framestart = object:GetKey(movement .. "_start", "")
               return object.framestart
       end

       function object:EndAnimations(movement)
               object.frameend = object:GetKey(movement .. "_end")
               return object.frameend
       end

And call the sequences I want depending on the movement message.

So I can call

object:StartAnimations("run")
object:EndAnimations("run")

 

An any animation that is called with the mesage will replace the ("") with the proper sequence.

 

Until I can find a better solution, this is what worked best for me,

AMD Phenom II x6 1100T - 16GB RAM - ATI 5870 HD - OCZ Vertex 2 60GB SSD

76561197984667096.png

Link to comment
Share on other sites

Ive snatched that bit of code and works pretty well :unsure: -

 

		if object.hasAnimations == true then -- character needs animation defined ... or else
			if object.move == 0 and object.currentanimation == AnimationIdle then
				self:StartAnimations("idle")
				self:EndAnimations("idle")
			end

			if object.move == 1 and object.currentanimation == AnimationJump and object.controller:IsAirborne() == 0 then
				self:StartAnimations("jump")
				self:EndAnimations("jump")
			end


			if object.move == 1 and object.currentanimation == AnimationWalk then
				self:StartAnimations("walk")
				self:EndAnimations("walk")
			end

			if object.move == 1 and object.currentanimation == AnimationRun then
				self:StartAnimations("run")
				self:EndAnimations("run")
			end
		end

My version is kind of horrid, though.

AMD 64 X2 Dual 5k - 4GB - XFX GForce9800GT - nv196.21 - WinXP Sp3

zBrush4R2 - Silo2Pro - Unwrap3DPro - Gile - MaPZone2.5

 

adv_banner-april2012_720x150_tex01.png

 

Xxploration FPS in progress ...

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