Data Realms Fan Forums
http://45.55.195.193/

RotateOffset based on LegFG
http://45.55.195.193/viewtopic.php?f=73&t=29678
Page 1 of 1

Author:  Mongoska [ Wed Jan 25, 2012 9:02 am ]
Post subject:  RotateOffset based on LegFG

Hello, my lovelies!

My knowledge of lua is very slim, but I'm trying to change the attached file slightly so that the following line bases my AEmitter's position on the actor's front leg, thus making the AEmitter both dependant on the ongoing existence of the leg and allowing it to be constantly situated near the leg at the same time.
Code:
      Emitter.Pos = self.Head.Pos + self.Head:RotateOffset(Vector(0, 36))

If this wouldn't make it dependant on the presence of the front leg, is it easy to do otherwise? If so, how?

For details on what I'm trying to do, see http://forums.datarealms.com/viewtopic.php?f=1&t=29666&p=458076.

Any assistance on the matter would be appreciated! Thanks!

Attachment:
Semi-Eyes.lua [1.5 KiB]
Downloaded 354 times

Author:  Abdul Alhazred [ Wed Jan 25, 2012 9:29 am ]
Post subject:  Re: RotateOffset based on LegFG

Here is an attempt at a solution. The code is not tested and I suspect you have to flip the emitter when the actor flips.
Code:
      
   if self.FGLeg then
      if self.FGLeg:IsAttached()      
         -- Validate emitter
         if not MovableMan:IsParticle(self.Emitter) or self.Emitter.PresetName ~= "TheNameOfTheEmitter" then
            self.Emitter = CreateAEmitter("TheNameOfTheEmitter", "TheNameOfTheRTE.rte")
            MovableMan:AddParticle(self.Emitter)
         end
      
         self.Emitter.Pos = self.FGLeg.Pos + self.FGLeg:RotateOffset(Vector(0, 36))
         self.Emitter.RotAngle = self.RotAngle
      else
         self.FGLeg = nil
      end
   elseif self.Emitter then   -- The leg is gone
      if MovableMan:IsParticle(self.Emitter) then
         self.Emitter.ToDelete = true
      end
      
      self.Emitter = nil
   end

I could not open the script you attached, so maybe you have already tried this.

Author:  Mongoska [ Wed Jan 25, 2012 4:40 pm ]
Post subject:  Re: RotateOffset based on LegFG

Ah... My lack of knowledge of lua is showing here... That code sounds like it is more or less what I'm after, but how might I integrate your code into mine (below)? Ideally I want the emitter's rotation to be based on the head, since I want to fire it like a gun, which I really didn't make clear in my description - rather than making a permanent addition to my leg consisting of an emitter, I'm trying to change a code which fires an emitter like a weapon from the head to one which fires it from the leg. The problem is that if I position it near the leg by offsetting it, it flies off when I move my head.

My difficulty in fixing it myself is that I don't quite understand how to define more than one body part for the object (this is my first attempt at editing an lua), which would be necessary for me to allow the emitter to rotate with the head.

I'm not sure why you couldn't open the lua, so I pasted it here. Thanks!

Code:
function Create(self)
   local thisID = ToActor(self).ID
   local MoObj
   for i = 1, MovableMan:GetMOIDCount() do
      if (i ~= thisID) and (MovableMan:GetRootMOID(i) == thisID) then -- an obj without a parent has ID == RootID
         MoObj = MovableMan:GetMOFromID(i)
         if MoObj.PresetName == "Maximilian Head" then -- Name of the actor's HEAD here.
            self.Head = ToAttachable(MoObj)
            break
         end
      end
   end
   
   self.fired = false;
end

function Update(self)
   if self:GetController():IsState(Controller.WEAPON_FIRE) and self.Head:IsAttached() and self.fired == false then
      local Emitter = CreateAEmitter("Maximilian Talon", "Maximilian.rte") -- Name of the emitter and .rte here.
      Emitter.Vel = self.Vel
   
      if self.HFlipped then
         Emitter.RotAngle = self.Head.RotAngle + 3.1415
      else
         Emitter.RotAngle = self.Head.RotAngle
      end
   
      Emitter.Pos = self.Head.Pos + self.Head:RotateOffset(Vector(0, 36)) -- Use self.EyePos instead? Probably no need.
      MovableMan:AddParticle(Emitter)
      self.fired = true;
   end
   if self:IsPlayerControlled() == false then
      self:GetController():SetState(Controller.BODY_CROUCH, false);
   end
   local Ctrl = self:GetController();
   if Ctrl:IsState(Controller.BODY_JUMPSTART) then
   else
      self.AngularVel = self.AngularVel * 0.75;
   end

   if not self:GetController():IsState(Controller.WEAPON_FIRE) then
      self.fired = false;
   end
end

Author:  Mongoska [ Thu Jan 26, 2012 12:04 am ]
Post subject:  Re: RotateOffset based on LegFG

Problem solved - I'm a fool! I hadn't realised quite how simple lua was - as soon as I looked into the syntax and stuff properly, I realised that the "self." variable was a fixed local one always relating to the actor carrying the script. I'd kinda assumed, since changing "Head" to "LegFG" hadn't worked, that "self." was being defined within the script, when of course it's not. The problem was that I was using "LegFG"... Which of course isn't a property - "FGLeg" was what I was after, which until I looked at it again I hadn't noticed in your script. *falls over* No wonder I was so confused!
Hehehe! What a nincompoop. Thanks for your help, anyhow! *blows kisses*

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/