Data Realms Fan Forums
http://45.55.195.193/

Relative Rotation of Attachments in Lua
http://45.55.195.193/viewtopic.php?f=73&t=32048
Page 1 of 1

Author:  Djinn [ Thu Nov 01, 2012 5:16 pm ]
Post subject:  Relative Rotation of Attachments in Lua

Hi, I've got attachables attached to a main body and I'm having them rotate through Lua - that works well enough, but I want them to rotate relative to the main body, because as it stands no matter how the main body turns their rotation is absolute. So presumably I have to somehow call the parent and do something like self.parent.RotAngle to get them to line up properly, but I can't seem to figure it out. Tips?

Code:
function Create(self)
   self.animTimer = Timer()
   self.frameChangeTime = 100
   self.RotSpeed = 0.3;
   self.count = 0
   self.flip = 0
   
end

function Update(self)
   
   if self.animTimer:IsPastSimMS(self.frameChangeTime) and self.flip == 0 then
      self.count = self.count + 1
      self.animTimer:Reset()
   elseif self.animTimer:IsPastSimMS(self.frameChangeTime) and self.flip == 1 then
      self.count = self.count - 1
      self.animTimer:Reset()
   end
   
   if self.count == 1 then
      self.RotAngle = 0
      self.flip = 0
   elseif self.count == 2 then
      self.RotAngle = 0.3
   elseif self.count == 3 then
      self.RotAngle = 0.7
   elseif self.count == 4 then
      self.RotAngle = 0.87
   elseif self.count == 5 then
      self.RotAngle = 1.05
   elseif self.count == 6 then
      self.RotAngle = 1.13
   elseif self.count == 7 then
      self.RotAngle = 1.22
   elseif self.count == 8 then
      self.RotAngle = 1.31
      self.flip = 1
   end
   
   
end


Here's the code I'm using, you can drop it on any attachable to see what I mean and see if you can help fix it.

Author:  Bad Boy [ Thu Nov 01, 2012 7:36 pm ]
Post subject:  Re: Relative Rotation of Attachments in Lua

General way to find a parent for an attachable:
Code:
   local actor = MovableMan:GetMOFromID(self.RootID);
   self.Parent = nil;

   if MovableMan:IsActor(actor) then
      self.Parent = ToActor(actor);
   end

After that, for simple rotation it should just be a matter of adding the parent rotangle to the desired rotangle change (I think). If you want to change position or velocity use something like Vector(x,y):RadRotate(self.Parent.RotAngle)

Author:  Djinn [ Thu Nov 01, 2012 9:09 pm ]
Post subject:  Re: Relative Rotation of Attachments in Lua

Bad Boy wrote:
General way to find a parent for an attachable:
After that, for simple rotation it should just be a matter of adding the parent rotangle to the desired rotangle change (I think). If you want to change position or velocity use something like Vector(x,y):RadRotate(self.Parent.RotAngle)


Man I don't know why you're called Bad Boy when you're so good!

So, it works perfectly, however I'm still getting errors in the console, despite that it works as intended:



Any idea why the heck that's happening and how it's working despite itself? Here's the code I'm using:


edit: Also, what if the parent of an attachable is a different attachable? How does the seeking code change in that case?

Author:  Djinn [ Fri Nov 02, 2012 12:19 am ]
Post subject:  Re: Relative Rotation of Attachments in Lua

Nonsequitorian wrote:
your problem may be that you make self.parent nil every click.

And, although it's most likely functionally implausible for the rootID to be an attachable unless its own parent was destroyed, there is no change in code.


Ah, maybe I should put it in create instead of update, eh?

As to your second point, is there a way of doing it so it COULD be used on an attachable? The problem I have now is that the fins rotate properly, but the attachable a attached to them do not. Those jerks.

Author:  Bad Boy [ Fri Nov 02, 2012 1:59 am ]
Post subject:  Re: Relative Rotation of Attachments in Lua

Here's a script that deals with making sure the parent is picked properly. Basically it puts a check on finding the parent in the update function so it won't keep doing it. The rest of it is a modified version of CC48's shield that I helped fix up for AndyChanglee's halo mod:
Attachment:
AESG.lua [4.6 KiB]
Downloaded 482 times

As for getting the attachable, this one here should help you. You'll need to get the parent actor first (i.e. what you have already) then get the attachable you want using this setup. There may be a way to do it more directly but I don't know it. The rest of it is some fun actor flight stuff for a project of my own, though it only works in 0 gravity:
Attachment:
Flight Pack.lua [6.84 KiB]
Downloaded 370 times


Quote:
Man I don't know why you're called Bad Boy when you're so good!
Aww thanks :) I'm always happy to help people with lua stuff, I just don't have enough time anymore. And yeah, it's an awful name, and I'd change it (and probably should) but the thought of going through all the various places I've registered with it and trying to change it is enough to keep me from actually doing it. For what it's worth, I picked it as a kid (about a decade ago, oh god!) when I thought it was super cool.

Edit: Hahaha I just noticed that you're using the braingfighter thing I made for you, that made the long night ahead of me a bit better. I'd look forward to seeing what you end up making :)

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