View unanswered posts | View active topics It is currently Thu Dec 26, 2024 4:37 pm



Reply to topic  [ 4 posts ] 
 RotateOffset based on LegFG 
Author Message
User avatar

Joined: Tue Jan 24, 2012 12:40 am
Posts: 37
Location: Weymouth, England
Reply with quote
Post 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 355 times


Last edited by Mongoska on Wed Jan 25, 2012 4:28 pm, edited 2 times in total.



Wed Jan 25, 2012 9:02 am
Profile
DRL Developer
DRL Developer

Joined: Tue Aug 11, 2009 5:09 am
Posts: 395
Reply with quote
Post 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.


Wed Jan 25, 2012 9:29 am
Profile
User avatar

Joined: Tue Jan 24, 2012 12:40 am
Posts: 37
Location: Weymouth, England
Reply with quote
Post 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


Wed Jan 25, 2012 4:40 pm
Profile
User avatar

Joined: Tue Jan 24, 2012 12:40 am
Posts: 37
Location: Weymouth, England
Reply with quote
Post 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*


Thu Jan 26, 2012 12:04 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.046s | 16 Queries | GZIP : Off ]