Data Realms Fan Forums
http://45.55.195.193/

Need the help of the lua gods!
http://45.55.195.193/viewtopic.php?f=1&t=29326
Page 1 of 1

Author:  Pantera1993 [ Thu Jan 12, 2012 3:30 am ]
Post subject:  Need the help of the lua gods!

I need a script that will hold a drop-ship a certain amount of pixels above the terrain. So if the terrain goes up, the craft goes up and the other way around. Maybe if it holds each engine above the terrain individually so if there's an incline the first side to hit it goes up, then the other side.

I'm not too sure if this is clear enough so if more information is needed ask me. Also, I very much appreciate any help that is given.

Author:  trystanr [ Thu Jan 12, 2012 10:42 am ]
Post subject:  Re: Need the help of the lua gods!

I'm not entirely sure what it is that you want.
From that, I understood to make it so that crafts are impossible to touch the ground?

Author:  Pantera1993 [ Thu Jan 12, 2012 8:41 pm ]
Post subject:  Re: Need the help of the lua gods!

Yeah, just to stay at a certain level right above the ground, like hovering just a few pixels above the ground.

Author:  Roast Veg [ Fri Jan 13, 2012 12:08 am ]
Post subject:  Re: Need the help of the lua gods!

You need to cast a ray to the closest piece of terrain, and make sure your Y position is however much above that.

Author:  Pantera1993 [ Fri Jan 13, 2012 1:17 am ]
Post subject:  Re: Need the help of the lua gods!

What would a script like that look like? I can't code in lua. :oops:

Author:  Roast Veg [ Fri Jan 13, 2012 6:30 pm ]
Post subject:  Re: Need the help of the lua gods!

Actually there's a better way to do that, MORays are a little more complicated than:
Code:
function Create(self)
    self.MaxHover = 15; --The maximum height above terrain the object will fly.
    self.MinHover = 10; --The minimum height it will fly.
end

function Update(self)
    self.Altitude = SceneMan:FindAltitude(self.Pos, 0, 2);
    if self.Altitude <= self.MaxHover then
         if self.Vel.Y = self.Vel.Y + 1;
    elseif self.Altitude >= self.MinHover then
        self.Vel.Y = self.Vel.Y -1;
    end
end
Pretty sure that should be bug free.

Author:  Pantera1993 [ Fri Jan 13, 2012 8:37 pm ]
Post subject:  Re: Need the help of the lua gods!

Thanks for the code Roast!

Code:
ERROR: Drop Ship Template.rte/hover.lua:9: 'then' expected near '='


Been attempting to fix this, but with no success...
EDIT:
Alright so, this seems to work well, perfectly actually....

Code:
function Create(self)
    self.MaxHover = 4; --The maximum height above terrain the object will fly.
    self.MinHover = 1; --The minimum height it will fly.
end

function Update(self)
    self.Altitude = SceneMan:FindAltitude(self.Pos, 0, 2);
    if self.Altitude < self.MaxHover then
        self.Vel.Y = self.Vel.Y + 1;
    elseif self.Altitude > self.MinHover then
        self.Vel.Y = self.Vel.Y -1;
    end
end


...but only when the AI is in control of the ship.

Author:  Roast Veg [ Sun Jan 15, 2012 8:15 pm ]
Post subject:  Re: Need the help of the lua gods!

Oh yeah that was crap copypasta by me there, sorry.

I can't explain why the code doesn't work without AI, it should all be the same.

Author:  Pantera1993 [ Sun Jan 15, 2012 8:29 pm ]
Post subject:  Re: Need the help of the lua gods!

I've run into another problem. The ship's altitude doesn't adjust according to the min/max hover variables. It just chooses an altitude and stays there no matter what the variables are telling it to do.

Author:  Skeggy [ Sun Feb 12, 2012 11:04 am ]
Post subject:  Re: Need the help of the lua gods!

I believe there is some sort of tilt hover system in S.A.Ws script if you still need.

Author:  HoneyFox [ Sun Feb 12, 2012 4:25 pm ]
Post subject:  Re: Need the help of the lua gods!

Pantera1993 wrote:
I've run into another problem. The ship's altitude doesn't adjust according to the min/max hover variables. It just chooses an altitude and stays there no matter what the variables are telling it to do.


check the logic of that script... it seems that there is some problems.

if self.Altitude < MaxHover then -- this "<" should be changed to ">" i think...
and
elseif self.Altitude > MinHover then -- this ">" should be changed to "<" ...

in CC, the Pos.Y is bigger when the actual position is lower... it is based on screen coordinate system i think.

and i'm not sure how is that Altitude calculated. will it always be a positive number?

Author:  Pantera1993 [ Tue Feb 14, 2012 4:39 am ]
Post subject:  Re: Need the help of the lua gods!

I'm pretty sure the altitude is measure in pixels, no?

Anyway, the code ended up working after applying it to the dropship itself instead of the engines.

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