Moving Polygons with Lua

Have a question, suggestion, or comment about Aleph One's features and functionality (Lua, MML, the engine itself, etc)? Post such topics here.
Post Reply
User avatar
heliomass
Born on Board
Posts: 42
Joined: Nov 3rd '13, 19:25
Location: Montréal, QC
Contact:

Hi,

I'm attempting to use Lua modify a polygon whilst a level is in play.

So, I can change the height of a polygon easily enough:

Code: Select all

Triggers = {}
function Triggers.idle()
        MoverUp()
end

-- Slowly move the floor of a polygon upwards until a threshold is
-- reached (rather like a platform raising from the ground)
--
function MoverUp()
        polygon = Polygons[54]
        if polygon.floor.height < 0.6 then
                polygon.floor.height = polygon.floor.height + 0.001
        end
end
However, I tried to get a polygon to move itself forward to no avail (without detaching itself from its surrounding polygons of course):

Code: Select all

Triggers = {}
function Triggers.idle()
        MoverForward()
end

-- Slowly edge a polygon forward to the edge of a room.
--
function MoverForward()
        polygon = Polygons[54]
        for e in polygon:endpoints() do
                e.x = e.x + 0.1
        end
end
I can see from the Lua documentation (https://aleph-wone.googlecode.com/hg/pr ... s/Lua.html) that the end points are read only, so I shouldn't really be surprised that it didn't work.

Does anyone know if there's a way to move the position of a polygon, or does the Aleph One engine render this stuff before the start of the level and we're stuck with it?
User avatar
Crater Creator
Vidmaster
Posts: 943
Joined: Feb 29th '08, 03:54
Contact:

Right. The engine handles x and y differently than it handles z. If you were able to change the xy coordinates of points at runtime, I imagine it would throw off all sorts of calculations, like texture mapping and AI pathing. It would be easy to make shapes the engine doesn't even consider valid polygons.

The only way I know of to achieve the effect you seek is to make a series of thin polygons and quickly raise or lower them (which would have other issues, like texture swimming).
User avatar
heliomass
Born on Board
Posts: 42
Joined: Nov 3rd '13, 19:25
Location: Montréal, QC
Contact:

The only way I know of to achieve the effect you seek is to make a series of thin polygons and quickly raise or lower them (which would have other issues, like texture swimming).
That was going to be my backup plan :D

I once achieved the effect using platforms, but I think it should be smoother to execute using Lua.

I always wondered how they achieved moving areas in other games (like Duke Nukem 3D, which appears to have an engine similar to Marathon, but allows moving areas like shuttle crafts and subway trains).

Wonder if it's possible to introduce into the Aleph One engine with some clever trickery?
User avatar
Crater Creator
Vidmaster
Posts: 943
Joined: Feb 29th '08, 03:54
Contact:

The devs can speak to this in more detail, but I think that would be less clever trickery and more engine overhaul. Now, if you don't mind going where few have gone before... I don't know what you want to move, but if it's a self-contained object like a car, you could make it a monster, give it a 3D model, and coax it into following a precise path. Its collision would still be cylindrical, however.
User avatar
heliomass
Born on Board
Posts: 42
Joined: Nov 3rd '13, 19:25
Location: Montréal, QC
Contact:

... you could make it a monster, give it a 3D model, and coax it into following a precise path.
Good idea, which I think demands a proof of concept. I'll have a try, and see how it goes.
User avatar
heliomass
Born on Board
Posts: 42
Joined: Nov 3rd '13, 19:25
Location: Montréal, QC
Contact:

OK, seems like a good approach. Here's a crude bit of code to move a monster back and forth along a polygon:

Code: Select all

Triggers = {}

monsterDirection = true

function Triggers.idle()
        monster = Monsters[0]
        monster.active = false
        if monsterDirection then
                if monster.x < Polygons[3].x then
                        monster:position(monster.x + 0.01, monster.y, monster.z, monster.polygon)
                else
                        monsterDirection = false
                        monster.yaw = 180
                end
        else
                if monster.x > 0 then
                        monster:position(monster.x - 0.05, monster.y, monster.z, monster.polygon)
                else
                        monsterDirection = true
                        monster.yaw = 0
                end
        end
end
And an equally crude video to show it in action:

https://dl.dropboxusercontent.com/u/8714314/mover.mp4

I set the physics for the monster so that it can't move, attack or do anything other than what the Lua tells it to.

Guess it's now a case of designing a 3D model to make it look like a vehicle, then we should be in business.

Thanks for the idea!
User avatar
Crater Creator
Vidmaster
Posts: 943
Joined: Feb 29th '08, 03:54
Contact:

No problem! To me, the idea's the easy part. It's usually followed by the original poster losing steam, and asking, "How do I do that? I don't get it. Can someone do this for me?"

So thank you for your tenacity. [MSmile] Your video demonstrates yet another of the potentially powerful things lua in Aleph One can do. For example, you could make the monster accelerate and decelerate smoothly, something normal monsters can't do.
User avatar
treellama
Vidmaster
Posts: 6107
Joined: Jun 2nd '06, 02:05
Location: Pittsburgh
Contact:

heliomass wrote:Does anyone know if there's a way to move the position of a polygon, or does the Aleph One engine render this stuff before the start of the level and we're stuck with it?
There's no way to move it right now.

Aleph One does precalculate a lot of stuff before the level starts, but it should be possible to update them as the game runs. There are other concerns, like preventing Lua from making polygons concave, or creating zero-length lines. You have to keep players, monsters, and items out of moving walls.

Endpoint coordinates are only read-only right now because nobody has figured out all those details.

As for your script, I think using a scenery object would be better as a vehicle. It wouldn't show up on the motion sensor, or chatter while you keep it inactive. Looking forward to seeing where you take this!
User avatar
heliomass
Born on Board
Posts: 42
Joined: Nov 3rd '13, 19:25
Location: Montréal, QC
Contact:

Aleph One does precalculate a lot of stuff before the level starts, but it should be possible to update them as the game runs. There are other concerns, like preventing Lua from making polygons concave, or creating zero-length lines. You have to keep players, monsters, and items out of moving walls.
It's true that there's only so far you can move a polygon around before one of the adjoining polygons becomes concave, or worse still inverted. That said, I reckon it would be the responsibility of the map designer to make sure they weren't creating such a situation. Would Aleph One just crash if a polygon became concave?
As for your script, I think using a scenery object would be better as a vehicle. It wouldn't show up on the motion sensor, or chatter while you keep it inactive.
Good idea. I assume scenery objects can be overridden with a 3D model and moved around in the same way as monsters?
Looking forward to seeing where you take this!
I'll definitely update this thread if I achieve something cool with this!
User avatar
Crater Creator
Vidmaster
Posts: 943
Joined: Feb 29th '08, 03:54
Contact:

Yeah, scenery shouldn't be any harder to replace with a 3D asset than a monster.

I'm reminded of one of the Killing Time tutorials that creates a moving vehicle illusion (link). It was made before lua was available, but you may find it instructive, or at least an interesting comparison.
User avatar
heliomass
Born on Board
Posts: 42
Joined: Nov 3rd '13, 19:25
Location: Montréal, QC
Contact:

Thanks, I shall have a read.

While I'm here, does anyone have a link to a tutorial or web page that explains the process for creating 3D models and applying them to Aleph One?
Post Reply