Data Realms Fan Forums http://45.55.195.193/ |
|
Dropship Hovering http://45.55.195.193/viewtopic.php?f=73&t=29530 |
Page 1 of 1 |
Author: | Pantera1993 [ Sun Jan 15, 2012 8:12 pm ] |
Post subject: | Dropship Hovering |
I got a problem with a script. I'm trying to have it keep my dropship at a certain altitude which is working fine but only when the AI is in control of the ship. I'd like to have it stay at that altitude even when I'm controlling the ship. Am I doing something wrong here or am I just missing a variable in the script? Code: function Create(self) self.Hover = 2; --The height it should hover. end function Update(self) self.Altitude = self.Hover; end I'm also having a problem with setting up the altitude of the ship. The script doesn't care what value I set to self.Hover, it keeps the ship hovering at some other value it likes. The altitude doesn't change if I change the variable... |
Author: | Abdul Alhazred [ Mon Jan 16, 2012 8:54 pm ] |
Post subject: | Re: Making a lua script run constantly |
Thats because there is no property called "Altitude" in the ACraft class or in the classes it inherits from. All you did was create a variable. If you want to know what properties you can manipulate with Lua, check the documentation. One possible solution would be to check the current altitude with FindAltitude and then move the ship up or down slightly if it is not close to the desired value. |
Author: | Pantera1993 [ Tue Jan 17, 2012 9:18 pm ] |
Post subject: | Re: Making a lua script run constantly |
Well I've been using this code courtesy of Roast Veg... Code: function Create(self) self.Hover = 2; end function Update(self) self.Altitude = SceneMan:FindAltitude(self.Pos, 0, 2); if self.Altitude < self.Hover then self.Altitude = self.Altitude+1; elseif self.Altitude > self.Hover then self.Altitude = self.Altitude-1; end end ...and it does the exact same thing. I'm attaching the code to the engines of the dropship as well, not the ship itself. |
Author: | Abdul Alhazred [ Wed Jan 18, 2012 12:51 am ] |
Post subject: | Re: Making a lua script run constantly |
The scrips you have posted do the same thing because they are equivalent. All they do is create a new variable called altitude, and then change the value of that variable. You should change the value of self.Pos.Y instead. About the engines; I'm not sure that will work because the engines are positioned relative to the body, not the other way around. So moving the engines might affect the body. If it does not work you could perhaps measure the altitude from two positions on the ship's body, calculate the angle and rotate the ship manually. |
Author: | Pantera1993 [ Wed Jan 18, 2012 4:17 am ] |
Post subject: | Re: Making a lua script run constantly |
Yup you were right, attaching to engines doesn't do it. I attached this to the dropship, and it just shoots it up into space. Code: function Create(self) self.Hover = 1; end function Update(self) self.Altitude = SceneMan:FindAltitude(self.Pos, 0, 1) if self.Altitude > self.Hover then self.Vel.Y = self.Vel.Y - 1; elseif self.Altitude < self.Hover then self.Vel.Y = self.Vel.Y + 1; end end The thing is I set the engines Particles Per Minute to 10, so it has to be the code doing this. |
Author: | Abdul Alhazred [ Wed Jan 18, 2012 8:31 am ] |
Post subject: | Re: Making a lua script run constantly |
The script says "lower Pos.Y, if the craft is more than one pixel above the ground". Since a Y-position of zero is at the top of the scene, the craft moves up. |
Author: | Pantera1993 [ Fri Jan 20, 2012 1:01 am ] |
Post subject: | Re: Making a lua script run constantly |
But I'm not setting the hover level according to any X or Y variable. I'm trying to set it via how many pixels findAltitude is finding. To me this script says "If I finds that the dropship is hovering at more than 2 pixels above ground, change the velocity it's traveling vertically to negative 1 until it reaches 2 pixels above ground and then do the same the other way around if that's the case." Am I reading this wrong? Edit: I also changed the post title to better suit the topic being discussed. |
Author: | TheLastBanana [ Fri Jan 20, 2012 1:37 am ] |
Post subject: | Re: Dropship Hovering |
Negative vertical velocity causes objects to move up. Positive vertical velocity causes objects to move down. When the altitude is greater than 1, you are decreasing vertical velocity. As a result, if the ship is hovering higher than 1 pixel above the ground, it moves upward. Your numbers are backward. |
Author: | Pantera1993 [ Fri Jan 20, 2012 5:56 am ] |
Post subject: | Re: Dropship Hovering |
Ahhhhh makes so much sense. Thanks!!! Edit: Alright, I got this code working well now. Thanks so much guys! |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |