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



Reply to topic  [ 9 posts ] 
 Dropship Hovering 
Author Message
User avatar

Joined: Wed Jul 06, 2011 5:11 pm
Posts: 226
Reply with quote
Post 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...


Last edited by Pantera1993 on Fri Jan 20, 2012 1:05 am, edited 3 times in total.



Sun Jan 15, 2012 8:12 pm
Profile
DRL Developer
DRL Developer

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


Mon Jan 16, 2012 8:54 pm
Profile
User avatar

Joined: Wed Jul 06, 2011 5:11 pm
Posts: 226
Reply with quote
Post 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.


Tue Jan 17, 2012 9:18 pm
Profile
DRL Developer
DRL Developer

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


Wed Jan 18, 2012 12:51 am
Profile
User avatar

Joined: Wed Jul 06, 2011 5:11 pm
Posts: 226
Reply with quote
Post 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.


Wed Jan 18, 2012 4:17 am
Profile
DRL Developer
DRL Developer

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


Wed Jan 18, 2012 8:31 am
Profile
User avatar

Joined: Wed Jul 06, 2011 5:11 pm
Posts: 226
Reply with quote
Post 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.


Fri Jan 20, 2012 1:01 am
Profile
DRL Developer
DRL Developer
User avatar

Joined: Wed Dec 13, 2006 5:27 am
Posts: 3138
Location: A little south and a lot west of Moscow
Reply with quote
Post 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.


Fri Jan 20, 2012 1:37 am
Profile WWW
User avatar

Joined: Wed Jul 06, 2011 5:11 pm
Posts: 226
Reply with quote
Post Re: Dropship Hovering
Ahhhhh makes so much sense. Thanks!!!

Edit: Alright, I got this code working well now. Thanks so much guys!


Fri Jan 20, 2012 5:56 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 9 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 | 13 Queries | GZIP : Off ]