Data Realms Fan Forums http://45.55.195.193/ |
|
Attached AHumans? http://45.55.195.193/viewtopic.php?f=73&t=14952 |
Page 1 of 1 |
Author: | Areku [ Mon May 25, 2009 4:20 pm ] |
Post subject: | Attached AHumans? |
I'm trying to make an actor that uses lua to set its position according to another actor's, like the dreadnought with turrets that P3lbox made. The difference is, I want the actors to attach or detach from each other based on a variable set by a pressed key. I've made this chunk of code: ( pasting it here messed it up a little) Code: function Create(self) -- The variables: self.LilBusters = false; end function Update(self) for actor in MovableMan.Actors do if actor:IsInGroup("LowLegs") then local avgx = actor.Pos.X - self.Pos.X; local avgy = actor.Pos.Y - self.Pos.Y; local dist = math.sqrt(avgx ^ 2 + avgy ^ 2); if self:IsPlayerControlled() and UInputMan:KeyPressed(18) and self.LilBusters == false then if dist < 50 then self.LilBusters = true; print ("LilBusters is ON"); end if self:IsPlayerControlled() and UInputMan:KeyPressed(18) and self.LilBusters == true then if dist < 50 then self.LilBusters = false; print ("LilBusters is OFF"); end end if self.LilBusters == true then self.Pos.X = actor.Pos.X; self.Pos.Y = actor.Pos.Y; end end end end end It doesn't work, for no apparent reason. No error messages appear, the actors don't attach, nothing happens at all. I know that the script is active, as I tried typing some random values between the variables, and that made error messages appear. Can anyone explain me what's wrong? |
Author: | Grif [ Mon May 25, 2009 6:56 pm ] |
Post subject: | Re: Attached AHumans? |
If it doesn't print then something's wrong with your logic statements. |
Author: | Areku [ Mon May 25, 2009 9:58 pm ] |
Post subject: | Re: Attached AHumans? |
After following Grif's advice and reviewing the statements, I came up with this much shorter and neater piece of code: Code: function Create(self) -- The variables: self.LilBusters = false; end function Update(self) for actor in MovableMan.Actors do local avgx = actor.Pos.X - self.Pos.X; local avgy = actor.Pos.Y - self.Pos.Y; local dist = math.sqrt(avgx ^ 2 + avgy ^ 2); if not actor.IsActor then if self.LilBusters == true then self.LilBusters = false; print ("LilBusters is OFF due to destruction"); end end -- if dist > 50 and self.LilBusters == true then -- self.LilBusters = false; -- print ("LilBusters is OFF due to distance"); -- end if actor:IsInGroup("LowLegs") and dist < 50 then if self:IsPlayerControlled() and self.LilBusters == false and UInputMan:KeyPressed(18) then self.LilBusters = true; print ("LilBusters is ON"); end if self:IsPlayerControlled() and self.LilBusters == true and UInputMan:KeyPressed(20) then self.LilBusters = false; print ("LilBusters is OFF due to manual activation"); end if self.LilBusters == true then self.Pos.X = actor.Pos.X; self.Pos.Y = actor.Pos.Y - 50; end end end end Then I put the two actors close to each other, pressed the "R" key and, surprisingly enough, it worked. The actors attached to each other. There was one... minor problem, though. The attached actor's limbs started to slowly descend, like gooey jelly dripping out from a dark green ice cube. While I was puzzled trying to decipher where that disgusting comparison I made originated itself, the upper actor's arm touched the lower actor's head. On less time that it takes to wink an eye, both actors accelerated to velocities rarely seen by human eyes, immediately covering the surrounding terrain with their blood and mutilated guts. As entertaining as that may be, it is not, by any means, what I intended them to do. Does someone know what is causing such effect? Any help is appreciated. (By the way, I made some experiments, and discovered that the farther one actor is from the other, the longer they take to explode, and the faster their body parts fly.) |
Author: | Grif [ Mon May 25, 2009 10:05 pm ] |
Post subject: | Re: Attached AHumans? |
That sounds hilarious, I'd say release it like that. |
Author: | Areku [ Mon May 25, 2009 10:18 pm ] | ||
Post subject: | Re: Attached AHumans? | ||
Sure, if you say so. To activate it, you have to buy the upper and lower parts, get them close to each other, select the upper part and then press R.
|
Author: | The Decaying Soldat [ Tue Jun 02, 2009 6:19 am ] |
Post subject: | Re: Attached AHumans? |
Very buggy. That poor guy is crushed after a few seconds after combination. |
Author: | Grif [ Tue Jun 02, 2009 3:06 pm ] |
Post subject: | Re: Attached AHumans? |
The Decaying Soldat wrote: Very buggy. That poor guy is crushed after a few seconds after combination. Awesome job reading there el capitan. |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |