View unanswered posts | View active topics It is currently Wed Dec 25, 2024 4:48 pm



Reply to topic  [ 5 posts ] 
 Relative Rotation of Attachments in Lua 
Author Message
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post 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.


Thu Nov 01, 2012 5:16 pm
Profile YIM

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post 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)


Thu Nov 01, 2012 7:36 pm
Profile
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post 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?


Thu Nov 01, 2012 9:09 pm
Profile YIM
User avatar

Joined: Sun Oct 29, 2006 4:26 am
Posts: 298
Reply with quote
Post 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.


Fri Nov 02, 2012 12:19 am
Profile YIM

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post 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 :)


Fri Nov 02, 2012 1:59 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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.048s | 14 Queries | GZIP : Off ]