Jump to content

Ragdoll


YouGroove
 Share

Recommended Posts

I've seen ragdolls implemented both in LE2 and LE3. So its possible. The only problem is getting the physics shapes and joints setup properly. That will depend on your model hierarchy (human bones vs. animals etc.). Dig the old community downloads section for an example in LE3.

Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)

Link to comment
Share on other sites

The only problem is getting the physics shapes and joints setup properly

In some engines ragdoll is simply based on bones, sometimes you need to do nothing or just adjust collision volumes.

Anyway having out of the box someday in LE3 would be good for all people making games with LE3, not only me wink.png

Stop toying and make games

Link to comment
Share on other sites

Thanks gamecreator, seeing video it lead mean to this thread with code examples :

http://www.leadwerks.com/werkspace/topic/5417-ragdolls/#entry47816

 

Hummm , that's heavy code wacko.png

--[[
Leadwerks Soldier Entity Script by Paul "Masterxilo" Frischknecht
(c) 2010 Paul Frischknecht/Hurricane-Eye Entertainment
visit http://www.hurricane-eye.webs.com/
=========Usage=========
This soldier model is designed to be controlled completely through messages.
It creates it's very own character controller and has all the animations set up.
All that is left to do is controlling it.
=========Messages=========
-Message-  -Parameters-  -Function-
"Jump"   N/A   Makes the character controller jump if it's on the ground.
"SetHeading"  "<y angle in °>" Sets the direction where the model should point/walk to when moving forward.
"SetMovement"  Any of:   Sets the correct animation and makes the character move.
  "MOVE_FORWARD"  If no movement is specified, the character will stop moving and play the idle animation.
  "MOVE_FORWARD_LEFT"
  "MOVE_FORWARD_RIGHT"
  "MOVE_BACK"
  "MOVE_BACK_LEFT"
  "MOVE_BACK_RIGHT"
  "MOVE_LEFT"
  "MOVE_RIGHT"
  ""
For an example of using the model, see the soldier game script.
Problems:
Animation of current lod stage resets after game mode of non-game soldiers... (only sometimes?!)
]]
-- Required scripts
require("Scripts/class")
require("Scripts/math/math")
require("Scripts/hooks")
require("Scripts/Constants/collision_const.lua")
-- Create the class
local class=CreateClass(...)
math.randomseed(AppTime())
-- Constants
class.NTSC_FPS    = 29.97
class.BLENDCHANGE_SPEED = 0.05
class.TURN_STEPS   = 5
class.MOVE_STEPS  = 3
class.MOVE_SPEED_FW  = 4.5
class.MOVE_SPEED_SIDE  = 3.2
class.MOVE_SPEED_BACK  = 3
class.JUMP_FORCE  = 4.0
class.animsLoaded  = 0
class.anims	    = {}
class.run_sound  = LoadSound('abstract::zombie.wav')
class.jump_sound = LoadSound('abstract::z_jump.wav')
zombie_mode = 0 --turn on or off zombie mode (chaising camera)
SetPhysicsQuality(0)
-- =======Animation handling=======
-- Loads an animation for all LoD's of the model and remember it's sequence id.
-- Per class (but requires one unique model instance)
function class:loadAnimation(model, animFilename, animId)
AppLog("Loading animation "..AbstractPath(animFilename).."...")
local sequenceId
--lodCount = CountChildren(model)
lodCount = CountModelLODEntities(model)--NEW as of LE2.5
for childId = 0, lodCount-1 do
 --sequenceId = LoadAnimation(GetChild(model, childId), animFilename)
 sequenceId = LoadAnimation(GetModelLODEntity(model,childId), animFilename)--NEW as of LE2.5
end
self[animId] = sequenceId
end
function class:clearAnimations(model)
ClearAnimation(model)
--lodCount = CountChildren(model)
lodCount = CountModelLODEntities(model)--NEW as of LE2.5
for childId = 0, lodCount-1 do
 --ClearAnimation(GetChild(model, childId))
 ClearAnimation(GetModelLODEntity(model, childId))--NEW as of LE2.5
end

class.animsLoaded = 0
end
-- Loads all animations (per class)
function class:loadAnimations(model)
class:clearAnimations(model)
class:loadAnimation(model, "abstract::anim_soldier_idle.gmf", "animIdleId")
class:loadAnimation(model, "abstract::anim_soldier_run.gmf", "animRunId")
class:loadAnimation(model, "abstract::anim_soldier_StrafeL.gmf", "animStrafeLId")
class:loadAnimation(model, "abstract::anim_soldier_StrafeR.gmf", "animStrafeRId")
class:loadAnimation(model, "abstract::anim_soldier_back.gmf", "animBackId")

-- Finished loading animations
class.animsLoaded = 1
AppLog("Loaded soldier animations.")
end
-- =======Class itself=======
function class:CreateObject(model)
-- Initialize
local object=self.super:CreateObject(model)
object.bodies  = {} --pysics bodies for ragdoll
object.joints  = {}
object.lods  = {}
object.lodCount = 0
--count and remember lods
--[[for childId = 1, CountChildren(model) do
 local child = GetChild(model, childId)
 if child:GetClass() == ENTITY_MESH then
  object.lodCount = object.lodCount + 1
  object.lods[object.lodCount] = child
 end
end]]

object.lodCount = CountModelLODEntities(model)
for childId = 0, object.lodCount-1 do
 local child = GetModelLODEntity(model, childId)
 object.lods[childId] = child
end
function object:CreateRagdoll()
 --AppLog("Start: "..os.time())
 self.ragdoll = 1 --turning on ragdoll and turning off animation
 --clear animation helper functions
 --RemoveHook("Flip", object.Render)
 object.Update = nil
 object.Draw = nil
 if self.controller ~= nil then
  FreeEntity(self.controller)
  self.controller = nil
 end
 --AppLog("Cleaning hooks and controller: "..os.time())

 --create a physics body for bone in model
 function CreateBodyForPart(partname, radius, length)
  local mesh = GetChild(self.model, 1) --taking a firts LOD for bones coordinates
  --local mesh = GetChild(GetModelLODEntity(self.model, 0), 1) --self.lods[0] --taking a firts LOD for bones coordinates
  local part = FindChild(mesh, partname)
  if part ~= nil then
   AppLog("Bone found: " .. partname)

   --[[
   --local body = CreateBodyPivot(self.model) --dosent work with collision
   --local body = CreateBodySphere(0.05, self.model)
   --local body = CreateBodySphere(radius, self.model)
   local body = CreateBodySphere(0.04, self.model)
   --local body = CreateBodyCylinder(radius, radius *  3, self.model)
   --local body = CreateBodyBox(radius * 3, length * 5, radius * 3, self.model)
   --SetBodyMassCenter(body, Vec3(0, radius *  1.5, 0))
   SweptCollision(body, 1)
   EntityType(body, COLLISION_PROP)
   --SetBodyGravityMode(body, 1)
   --SetBodyFriction(body, 0.1, 0.1)
   --SetBodySoftness(body, 1)
   --SetBodyElasticity(body, 1)
   --SetBodyDamping(body, 0.3, 0.3)
   SetBodyMass(body, radius * 500)
   --SetBodyMass(body, 5)

   PositionEntity(body, EntityPosition(part, 1), 1)
   RotateEntity(body, EntityRotation(part, 1), 1)
   self.bodies[partname] = body
   ]]



   --cylinder doesn't work because of can't shift it without shiftion it's origin

   --creating a bone-like body
   --local bone = CreateBodyBox(radius * 3, length, radius * 3, body)
   local bone = CreateBodyBox(radius * 2, length - 0.04, radius * 2, nil)
   --local bone = CreateBodyCylinder(radius, length,  --self.model)
   --local bone = CreateBodyCylinder(radius, length - 0.04,  nil) --body)

   local position = EntityPosition(part, 1)
   --local position = Vec3(origin.x, origin.y -length / 2 - 0.04, origin.z)
   PositionEntity(bone, position, 1)
   RotateEntity(bone, EntityRotation(part, 1), 1)

   TurnEntity(bone, Vec3(90, 90, 0))
   MoveEntity(bone, Vec3(0, -length / 2 - 0.04, 0), 1)
   --TranslateEntity(bone, Vec3(0, -length / 2 - 0.04, 0), 0)

   --SetEntityMatrix(bone, GetEntityMatrix(part))
   EntityType(bone, COLLISION_PROP)
   SweptCollision(bone, 1)
   --SetBodyGravityMode(bone, 1)
   --SetBodyMassCenter(bone, Vec3(0, radius *  1.5, 0))
   --SetBodyFriction(bone, 0.5, 0.5)
   --SetBodyFriction(bone, 0.3, 0.3)
   SetBodyFriction(bone, 0.8, 0.3)
   --SetBodySoftness(bone, 1)
   --SetBodyElasticity(bone, 1)
   --SetBodyDamping(bone, 0.3, 0.3)
   --SetBodyMass(bone, radius * 50)
   SetBodyMass(bone, radius * 200)
   --SetBodyMass(bone, 5)

   --self.bodies[partname] = body
   self.bodies[partname] = bone

   --CreateJointFixed(body, bone, EntityPosition(body, 1))
   --EntityParent(body, self.bodies[partname], 1)
   --EntityParent(bone, body, 1)
   --EntityParent(self.bodies[partname], nil, 1)
  else
   AppLog("Bone not found: " .. partname)
  end
 end
 function SetupBodyForPart(mesh, partname)
  local part = FindChild(mesh, partname)
  if part ~= nil then
   EntityParent(part, self.bodies[partname], 1)
   AppLog("Part found: " .. partname)
  else
   AppLog("Part not found: " .. partname)
  end
 end
 function CreateJoint(bodyname_parent, bodyname_child, pin, minangle, maxangle)
  --local joint = CreateJointBall(self.bodies[bodyname_parent], self.bodies[bodyname_child], EntityPosition(self.bodies[bodyname_parent], 1))
  --local joint = CreateJointBall(self.bodies[bodyname_child], self.bodies[bodyname_parent], EntityPosition(self.bodies[bodyname_parent], 1))
  --local joint = CreateJointBall(self.bodies[bodyname_parent], self.bodies[bodyname_child], EntityPosition(self.bodies[bodyname_child], 1))
  --local joint = CreateJointBall(self.bodies[bodyname_child], self.bodies[bodyname_parent], EntityPosition(self.bodies[bodyname_child], 1))

  local axe = TFormVector(pin, self.model, nil)
  --local position = EntityPosition(self.bodies[bodyname_child], 1)
  local position
  --local mesh = GetModelLODEntity(self.model, 0) --self.lods[0] --taking a firts LOD for bones coordinates
  local mesh = GetChild(self.model, 1)
  --TellAboutChildren(mesh, 0)
  local part = FindChild(mesh, bodyname_child)
  if part ~= nil then
   position = EntityPosition(part, 1)
   AppLog("Part "..bodyname_child.." found.")
  else
   AppLog("Part "..bodyname_child.." not found!")
  end
  local joint = CreateJointHinge(self.bodies[bodyname_parent], self.bodies[bodyname_child], position, axe)
  SetHingeJointLimits(joint, minangle, maxangle)
  --SetJointCollisionMode(joint, 0) --dosen't work in lua
  --SetBallJointLimits(joint, Vec3(1,1,1), 0, 0) --dosen't work in lua
  --joint:SetLimits(Vec3(1, 1, 1), 0, 0) --dosen't work

  self.joints[bodyname_child] = joint
  --EntityParent(joint, self.bodies[bodyname_parent])
 end
 --reset all lods position
 --[[for childId = 0, self.lodCount-1 do
  local child = self.lods[childId]
  PositionEntity(child, EntityPosition(self.model, 1), 1)
  RotateEntity(child, EntityRotation(self.model, 1), 1)
  UpdateMesh(child)
 end]]
 --AppLog("Updating lods: "..os.time())

 AppLog("Creating bodies for parts...")
 CreateBodyForPart("Bip01 Pelvis", 0.05, 0.08)
 CreateBodyForPart("Bip01 Spine", 0.03, 0.13)
 CreateBodyForPart("Bip01 Spine1", 0.03, 0.13)
 CreateBodyForPart("Bip01 Spine2", 0.02, 0.13)
 CreateBodyForPart("Bip01 Neck", 0.03, 0.06)
 CreateBodyForPart("Bip01 Head", 0.08, 0.1)

 CreateBodyForPart("Bip01 L Clavicle", 0.02, 0.15)
 CreateBodyForPart("Bip01 R Clavicle", 0.02, 0.15)
 CreateBodyForPart("Bip01 L UpperArm", 0.03, 0.28)
 CreateBodyForPart("Bip01 R UpperArm", 0.03, 0.28)
 CreateBodyForPart("Bip01 L Forearm", 0.03, 0.21)
 CreateBodyForPart("Bip01 R Forearm", 0.03, 0.21)
 CreateBodyForPart("Bip01 L Hand", 0.03, 0.09)
 CreateBodyForPart("Bip01 R Hand", 0.03, 0.09)

 CreateBodyForPart("Bip01 L Thigh", 0.06, 0.38)
 CreateBodyForPart("Bip01 R Thigh", 0.06, 0.38)
 CreateBodyForPart("Bip01 L Calf", 0.04, 0.36)
 CreateBodyForPart("Bip01 R Calf", 0.04, 0.36)
 CreateBodyForPart("Bip01 L Foot", 0.04, 0.08)
 CreateBodyForPart("Bip01 R Foot", 0.04, 0.08)
 AppLog("Intializing joints...")

 local rollX = Vec3(1, 0, 0)
 local rollY = Vec3(0, 1, 0)
 local rollZ = Vec3(0, 0, 1)

 CreateJoint("Bip01 Pelvis", "Bip01 Spine", rollY, -45, 45)
 CreateJoint("Bip01 Spine", "Bip01 Spine1", rollX, -10, 30)
 CreateJoint("Bip01 Spine1", "Bip01 Spine2", rollX, -10, 30)
 CreateJoint("Bip01 Spine2", "Bip01 Neck", rollX, -10, -10)
 CreateJoint("Bip01 Head", "Bip01 Neck", rollY, -75, 75)


 CreateJoint("Bip01 Neck", "Bip01 L Clavicle", rollY, -30, 0)
 CreateJoint("Bip01 Neck", "Bip01 R Clavicle", rollY, 0, 30)
 CreateJoint("Bip01 L Clavicle", "Bip01 L UpperArm", rollZ, -140, 0)
 CreateJoint("Bip01 R Clavicle", "Bip01 R UpperArm", rollZ, 0, 140)
 CreateJoint("Bip01 L UpperArm", "Bip01 L Forearm", rollX, -120, 0)
 CreateJoint("Bip01 R UpperArm", "Bip01 R Forearm", rollX, -120, 0)
 CreateJoint("Bip01 L Forearm", "Bip01 L Hand", rollZ, -5, 30)
 CreateJoint("Bip01 R Forearm", "Bip01 R Hand", rollZ, -30, 5)

 CreateJoint("Bip01 L Thigh", "Bip01 Pelvis", rollX, -5, 90)
 CreateJoint("Bip01 R Thigh", "Bip01 Pelvis", rollX, -5, 90)
 CreateJoint("Bip01 L Thigh", "Bip01 L Calf", rollX, 10, 140)
 CreateJoint("Bip01 R Thigh", "Bip01 R Calf", rollX, 10, 140)
 CreateJoint("Bip01 L Calf", "Bip01 L Foot", rollX, -10, 60)
 CreateJoint("Bip01 R Calf", "Bip01 R Foot", rollX, -10, 60)
 --AppLog("Creating joints: "..os.time())

 --for childId = 0, CountModelLODEntities(self.model)-1 do
  --local child = GetChild(GetModelLODEntity(self.model, childId), 1)
  local child = GetChild(self.model, 1)
  AppLog("Setting up bodies...")
  SetupBodyForPart(child, "Bip01 L Foot")
  SetupBodyForPart(child, "Bip01 R Foot")
  SetupBodyForPart(child, "Bip01 L Calf")
  SetupBodyForPart(child, "Bip01 R Calf")
  SetupBodyForPart(child, "Bip01 L Thigh")
  SetupBodyForPart(child, "Bip01 R Thigh")
  SetupBodyForPart(child, "Bip01 L Hand")
  SetupBodyForPart(child, "Bip01 R Hand")
  SetupBodyForPart(child, "Bip01 L Forearm")
  SetupBodyForPart(child, "Bip01 R Forearm")
  SetupBodyForPart(child, "Bip01 L UpperArm")
  SetupBodyForPart(child, "Bip01 R UpperArm")
  SetupBodyForPart(child, "Bip01 L Clavicle")
  SetupBodyForPart(child, "Bip01 R Clavicle")
  SetupBodyForPart(child, "Bip01 Head")
  SetupBodyForPart(child, "Bip01 Neck")
  SetupBodyForPart(child, "Bip01 Spine2")
  SetupBodyForPart(child, "Bip01 Spine1")
  SetupBodyForPart(child, "Bip01 Spine")
  SetupBodyForPart(child, "Bip01 Pelvis")
 --end
end --object:CreateRagdoll()
function object:ClearJoints()
 local id
 for id in pairs(self.joints) do
  FreeJoint(self.joints[id])
 end
 for id in pairs(self.bodies) do
  FreeEntity(self.bodies[id])
 end
end
function object:updateAnimation()
 local blend = AppSpeed() * class.BLENDCHANGE_SPEED
 blend = math.min(blend, 1.0)
 --AppLog("CountChildren = "..CountChildren(self.model))
 --AppLog("CountLODs = "..CountModelLODEntities(self.model))
 Animate(self.model,
  ((AppTime()+self.timeOffset)/1000.0) * class.NTSC_FPS, blend,
  self.currentAnim-1, 1)
 --[[for childId = 0, CountModelLODEntities(self.model)-1 do
  local child = GetModelLODEntity(model, childId)
  Animate(child, --self.model,
   ((AppTime()+self.timeOffset)/1000.0) * class.NTSC_FPS, blend,
   self.currentAnim-1, 1)
 end]]
end
-- Initialize function
function object:Init()
 -- Load this model class' anims (has to be done only once)
 if class.animsLoaded==0 then
  class:loadAnimations(model)
 end

 -- Setup the model
 SetModelLODDistance(model, 5, 0)
 SetModelLODDistance(model, 12, 1)
 SetModelLODDistance(model, 19, 2)
 -- Collision type
 EntityType(model, COLLISION_NONE)
 --local lodCount = CountChildren(model)
AppLog("Setting physics...")
 local lodCount = CountModelLODEntities(model)--NEW as of LE2.5
AppLog("LOD count = "..lodCount)
 for childId = 0, lodCount-1 do
  --EntityType(GetChild(model, childId), COLLISION_AILINEOFSIGHT)
AppLog("Setting LOD "..childId)
  EntityType(GetModelLODEntity(model, childId), COLLISION_AILINEOFSIGHT)--NEW as of LE2.5
 end
AppLog("Setting physics done.")

 self.target  = fw.main.camera --for zombie mode
 self.life  = 100 --for countdown hits until death
 -- Set default settings
 self.moveDirAdd    = 0
 self.curMoveDirAdd = 0
 self.moveDir    = 0
 self.moveSpeed	 = 0
 self.jump	 = 0
 self.matrixUpdateIsInternal = 0
 -- Animations
 self.currentAnim = 0
 self.timeOffset  = math.random(10000)
 -- Create the controller
 self.controller = CreateController(1.75, 0.35, 0.45, 45, 1)
 PositionEntity(self.controller, EntityPosition(model, 1), 1)
 SetBodyMass(self.controller, 10)
 EntityType(self.controller, COLLISION_CHARACTER)
 SweptCollision(self.controller, 1 )
 -- Set current state
 SendEntityMessage(model, "SetMovement=")
 SendEntityMessage(model, "SetHeading=0")
 SendEntityMessage(model, "RandomizeAnimTimeOffset", nil,1)

 self.ragdoll = 0
end
-- Define callbacks
function object:SetKey(key,value)
 if key=="color" then
 else
  return self.super:SetKey(key,value)
 end
 return 1
end
--[[function object:GetKey(key,value)
 if key=="bloody" then
  return "true"
 end
end]]
function object:SetMovement(moveDirAdd, moveDir, moveSpeed, currentAnim)
 self.moveDirAdd    = moveDirAdd
 self.moveDir    = moveDir
 self.moveSpeed	 = moveSpeed
 self.currentAnim   = self.class[currentAnim]
end

-- Recieve control commands through messages
function object:ReceiveMessage(message,extra)
 local values=string.Explode(message,"=")
 local command = values[1]
 local value = ""
 if values[2] ~= nil then value = values[2] end

 if command=="SetHeading" then
  self.heading = tonumber(value)

 elseif command=="Jump" then
  if self.ragdoll == 0 then --don't jump after death
   if ControllerAirborne(self.controller) == 0 then --don't jump in air
 self.jump = 1
 self.model:EmitSound(self.class.jump_sound, 30, 1.0, 0)
   end
  end

 elseif command=="hit" then
  if self.ragdoll == 0 then --still alive
   AppLog("I'm hited!")
   self.life = self.life - 1000
   if self.life <= 0 then
 SendEntityMessage(self.model, "die")
   else
 local volume = 1.0 - self.life * 0.005
 self.model:EmitSound(self.class.jump_sound, 30, volume, 0)
   end
  end

 elseif command=="die" or command=="use" then
  AppLog("I'm dying!")
  self.currentAnim = self.class.animIdleId
  self:updateAnimation()
  self:CreateRagdoll()
  AppLog("I'm dead!")

 elseif command=="SetMovement" then
  if value=="MOVE_FORWARD" then
   self:SetMovement(0, 0, class.MOVE_SPEED_FW, "animRunId")

  elseif value=="MOVE_FORWARD_LEFT" then
   self:SetMovement(45, 0, class.MOVE_SPEED_FW, "animRunId")

  elseif value=="MOVE_FORWARD_RIGHT" then
   self:SetMovement(-45, 0, class.MOVE_SPEED_FW, "animRunId")

  elseif value=="MOVE_BACK" then
   self:SetMovement(0, 180, class.MOVE_SPEED_BACK, "animBackId")

  elseif value=="MOVE_BACK_LEFT" then
   self:SetMovement(-45, 180, class.MOVE_SPEED_BACK, "animBackId")

  elseif value=="MOVE_BACK_RIGHT" then
   self:SetMovement(45, 180, class.MOVE_SPEED_BACK, "animBackId")

  elseif value=="MOVE_LEFT" then
   self:SetMovement(0, 90, class.MOVE_SPEED_SIDE, "animStrafeLId")

  elseif value=="MOVE_RIGHT" then
   self:SetMovement(0, -90, class.MOVE_SPEED_SIDE, "animStrafeRId")

  else
   self:SetMovement(0, 0, 0, "animIdleId")
  end

 else
  return self.super:ReceiveMessage(message,extra)
 end
 return 0
end
-- Update the model. That is, update the roation and move/jump if necessary.
function object:Update()
 if zombie_mode == 1 then
  local selfposition = EntityPosition(model)
  local cameraposition = EntityPosition(self.target)
  local distance = EntityDistance(model, self.target)
  if distance > 15 then
   if self.moveSpeed ~= 0 then
 SendEntityMessage(model, "SetMovement=")
   end
   self.heading = self.heading + 1
  else
   self.heading = math.atan2(cameraposition.z - selfposition.z, cameraposition.x - selfposition.x) * 180 / math.pi - 90
   if distance > 3 then
 if self.moveSpeed == 0 then
  self.model:EmitSound(self.class.run_sound,30,1.0,0)
 end
 SendEntityMessage(model, "SetMovement=MOVE_FORWARD")
   else
 if self.moveSpeed ~= 0 then
  SendEntityMessage(model, "SetMovement=")
 end
 self.heading = self.heading + 1
 --AppLog("rotating...")
   end

   if distance < 5 and self.moveSpeed ~= 0 then
 SendEntityMessage(model, "Jump")
   end
  end
 end
 self.matrixUpdateIsInternal = 1
 -- Update directions
 self.curMoveDirAdd = CurveAngle(self.moveDirAdd, self.curMoveDirAdd, class.TURN_STEPS*(1.0/AppSpeed()))
 --if self.moveSpeed > 0.0 then
  self.curHeading = CurveAngle(self.heading, self.curHeading,  class.TURN_STEPS*(1.0/AppSpeed()))
 --end
 RotateEntity(model, Vec3(0, self.curHeading+self.curMoveDirAdd+180, 0))

 self.controller:Update(self.curHeading + self.moveDir + self.curMoveDirAdd, self.moveSpeed, 0, self.jump*class.JUMP_FORCE, 500, 1, 0)
 self.jump = 0
 local curpos = EntityPosition(model)
 targetPos = EntityPosition(self.controller)
 curpos.x = Curve(targetPos.x, curpos.x, class.MOVE_STEPS*(1.0/AppSpeed()))
 curpos.y = Curve(targetPos.y, curpos.y, class.MOVE_STEPS*(1.0/AppSpeed()))
 curpos.z = Curve(targetPos.z, curpos.z, class.MOVE_STEPS*(1.0/AppSpeed()))
 PositionEntity(model, curpos)
 self.matrixUpdateIsInternal = 0
end
-- Render update. Plays the animations.
function object:Draw()
 object.matrixUpdateIsInternal = 1
 -- Update animations
 object:updateAnimation()
 object.matrixUpdateIsInternal = 0
end
-- External movement and rotation requires special threatment since the model is controlled by a cc.
function object:UpdateMatrix()
 if self.matrixUpdateIsInternal == 0 then
  -- Force heading
  self.heading = EntityRotation(self.model).y-180
  self.curHeading = self.heading
  self.moveDirAdd = 0

  -- Force position
  if self.controller ~= nil then
   PositionEntity(self.controller, EntityPosition(self.model))
  end
 end
end
function object:Reset()
 self.matrixUpdateIsInternal = 0
 object:UpdateMatrix()
end
-- Free callback. Frees the model and the cc.
function object:Free(model)
 --RemoveHook("Flip", object.Render)
 --free all bodies
 self:ClearJoints()
 if self.controller ~= nil then
  FreeEntity(self.controller)
 end
 self.super:Free()
end
-- Call initialize func
object:Init()
--AddHook("Flip", object.Render)
SendEntityMessage(object.model, "die", nil, 5000) --let's kill him
end

Stop toying and make games

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