Slashdot Log In
Examining Portal's Teleportation Code
Posted by
Soulskill
on Tue Aug 26, 2008 01:55 PM
from the wall-to-wall-coverage dept.
from the wall-to-wall-coverage dept.
Gamasutra is running a story deconstructing the mechanics of Portal's teleportation programming. They present a snippet of Portal's code and a downloadable demo. They ran another article in this series earlier this year with an analysis Mario Galaxy's unique take on physics. We've discussed the development of Portal in the past.
"Teleport mechanics in video games are nothing new. Puzzles from the original Gauntlet were memorable -- and more than likely, that wasn't the first game to use teleportation as a gameplay mechanic. The difference between Portal and all those that came before it is that Portal's teleportation acts as a frictionless tube between point A and point B. Physics are still hard at work inside the frictionless tube. Instead of simply repositioning an object from point A to point B, the player enters point A with full velocity and exits point B with the same speed, but moving in a new direction."
Update: 8/26 at 19:37 by SS: Dan notes that the code was not directly from Portal; it was written to approximate Portal's physics.
Related Stories
[+]
A Peek Through Portal's Walls 42 comments
John Walker, of Rock, Paper, Shotgun, had the chance to chat with some of the principal folks behind Valve's most excellent puzzle/shooter hybrid Portal. He comes away with the goods from lead designers Kim Swift and Jeep Barrett, who discuss their momentous hiring by Valve, the evolution of Portal from Narbacular Drop, and the origins of the Weighted Companion Cube. Walker also talks to Erik Wolpaw, who not only wrote Portal but was co-writer on Psychonauts and the site Old Man Murray (back in the day). From that discussion: "Valve talks a lot about 'collective design process this' and 'collective design process that' to the point where, if I were me before I worked here and stopped swearing so much, I'd be like, this is some fake-ass marketing-ass Bigfoot-ass legendary bullshit. But, honest-to-God, I've seen it with my own eyes. Valve is the most collaborative creative environment I've ever heard of much less experienced. So the [Team Fortress 2] shorts grew out of basically everyone at Valve's desire to see these awesome TF characters put through their paces outside the constraints of the game. We did the Heavy as a proof of concept, and kind of freaked ourselves out, and then immediately decided to move ahead with the other eight."
This discussion has been archived.
No new comments can be posted.
The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
Full
Abbreviated
Hidden
Loading... please wait.
Frictionless tube? (Score:5, Funny)
Your mom has a frictionless tube.
First post?
Re:Frictionless tube? (Score:5, Funny)
For friction to be present, the object being inserted into the tube must be large enough to touch the sides. That must be your problem.
Parent
Re:Frictionless tube? (Score:5, Funny)
For friction to be present, the object being inserted into the tube must be large enough to touch the sides. That must be your problem.
THAT'S WHAT SHE SAID! -er, shit. *self pwn*
Parent
Portal (Score:5, Funny)
Re:Portal (Score:5, Informative)
Duke Nukem 3D's teleporters would teleport your weapon shots, too.
I loved shooting the rocket launcher into it only to hear a buddy die on the other side of the map as the rocket appeared and continued on its way.
I don't recall if you jumped into the teleporter if you'd exit and continue your jump arc, but there is precident for "movement in progress" teleportation.
Parent
Re:Portal (Score:5, Interesting)
That's not entirely correct, from a programming standpoint.
In most old games, "physics" were limited to jumping (and, occasionally, explosions knocking players around). Rather than try to simulate ballistic trajectories for every object in the game, rockets and other projectiles were simply moved forward a certain distance for every "tick" of game time.
So the transporter didn't preserve the rocket's momentum - it just put the rocket at a new location, and the game then resumed moving the rocket forward.
Parent
It's exactly the same. (Score:5, Insightful)
So the transporter didn't preserve the rocket's momentum - it just put the rocket at a new location, and the game then resumed moving the rocket forward.
From a engine coding point of view, i fail to see how there's any difference.
In both cases, you have a vector attached to an object which describes how an object move :
- you can call it "trajectory" for shots
- you can call it "momentum" for portal
but technically it's just plain stupid "speed" vector. As in "derivative of the position" (= how the position is updated between each turn).
Eventually, if it's not a rocket, it will also obey to an acceleration (most of the time : gravity. But it can be buoyancy).
In both situation, all you have to do for any object entering a teleport, is simply change the current coordinate of the object, and eventually perform a transformation on the speed vector if both teleport end point aren't facing the same direction.
From a coding point of view portal doesn't introduce anything new for the physics that wasn't already done by any of all the multiple game that allow shooting through a portal or *jumping* through a teleport.
The new thing are the rendering engine (not all engine can easily render see-through portals - due to the way the work, Duke 3D's and Descent [portal based] and Wolfenstein and Doom [raycasting] could do them, but Quake 1 & 2 [BSP polygons] can't)
and the gameplay (before portal, teleporting thing other than the player was a fun by-product of how teleport work and can enable a couple of giggles. Portal in contrast has all its puzzle based around throwing object through portals)
Parent
Re: (Score:3, Funny)
Note that, in Portal, execution and cake seem to be linked...
Re:Portal (Score:5, Interesting)
I don't recall if you jumped into the teleporter if you'd exit and continue your jump arc,
To some extent, I'd guess. It wouldn't be perfect, but let me put it this way: Duke 3D was a two-and-a-half-D game, not a 3D game.
This implies, among other things, that the engine didn't actually support rooms on top of one another -- that all had to be faked in some way.
So how could you swim underwater? The simple answer is, the surface of the water was a silent teleporter -- it might even have to be marked "water" -- and the "underwater" was actually a completely different place in the map.
Going upstairs was a different trick -- the fact that the game could handle two rooms, or "sectors", occupying the same space, so long as you couldn't see both at once. There was a lot of really creative level design involving staircases and the like to make it seem as though you had a two-story building, while never actually letting you see both stories at once.
If you want to get a really good idea of what the Duke3D engine was, find one of the secret levels -- the one with a big room in the middle, and a hallway ringing around the outside (kind of a donut shape) -- don't remember what it was called. I do remember that you could turn right three times, and end up in a different room -- there were four separate rooms (or "sectors") set in the same physical space.
Parent
Re:Portal (Score:5, Funny)
First thought: "Hey, if it can work within or near the event horizon of a black hole we could time travel!".
Second thought: "Wound this violate one of the laws of thermodynamics?"
Third thought: "I need a life."
Parent
But... (Score:5, Funny)
But... can they telefrag?
I just love the sound of 2 bodies trying to occupy the same space at the same time in the morning... or afternoon... or evening...
Too verbose (Score:5, Funny)
>>Physics are still hard at work inside the frictionless tube. Instead of simply repositioning an object from point A to point B, the player enters point A with full velocity and exits point B with the same speed, but moving in a new direction."
Should be "Speedy thing goes in; speedy thing comes out."
Re:Too verbose (Score:5, Funny)
Parent
No kidding (Score:3, Insightful)
No kidding. The whole "frictionless tube" thing is just thinking too hard about it. Yes, instead of simply repositioning an object from point A to point B, you also take the normal of both holes and change the direction of the velocity. That's it. It solves the same problem and produces the exact same result without doing physics for a frictionless tube.
Ahoy, GlaDOS! (Score:5, Funny)
Re:Ahoy, GlaDOS! (Score:5, Funny)
I'm waiting on the hot grits version, Portman
Parent
Re:Ahoy, GlaDOS! (Score:5, Funny)
-Rowley Birkin, QC
Parent
Re:Ahoy, GlaDOS! (Score:5, Funny)
I'm waiting on the drunken lawyer version, Port
I'm waiting for the Wii version, P.
Parent
Re:Ahoy, GlaDOS! (Score:5, Funny)
Parent
Re: (Score:3, Funny)
Physics is Phun (Score:4, Interesting)
A well made 2D Flash version of Portal:
http://portal.wecreatestuff.com/portal.php [wecreatestuff.com]
Not really (Score:3, Insightful)
Started neat but quickly degenerated in to something all to typical with flash games: You have to have really fast reflexes and figure you the logic apparent only to the designer. Neat technically, but the gameplay needs work.
M.C.Escher has good OLD examples of the concept: (Score:4, Interesting)
http://www.mcescher.net/images/relativity.jpg [mcescher.net] (1953)
and
http://www.mcescher.net/images/houseofstairs.jpg [mcescher.net] (1951)
Re:M.C.Escher has good OLD examples of the concept (Score:5, Funny)
Speaking of, whens he gonna put a new album out?
Are you talking about M.C. Escher who designed the crazy staircase house? Or David Bowie, who lives there?
Parent
Damn! (Score:5, Insightful)
Reading that article makes me want to play Portal through again.
--sigh-- at least it won't take long.
Re: (Score:3, Informative)
Try this. [wecreatestuff.com] They claim it's 3.5 hours of game time, but the puzzles are *hard*, so it takes more like a day.
Next step? (Score:4, Funny)
Porting Portal's portal code?
Re:Next step? (Score:5, Funny)
I'm a portal porter's son
And i'm only porting portal
Till the portal porter comes
Parent
WTF (Score:5, Insightful)
The difference between Portal and all those that came before it is that Portal's teleportation acts as a frictionless tube between point A and point B. Physics are still hard at work inside the frictionless tube. Instead of simply repositioning an object from point A to point B, the player enters point A with full velocity and exits point B with the same speed, but moving in a new direction.
Are you fucking kidding? What's not completely obvious about this algorithm that should be Slashdot-front page worthy? I mean, it's fucking mind blowingly obvious, of course it keeps the velocity and translates it, how else could it do what it does? I can understand why it would be relevant to do a coding tutorial on the subject, but that's about as newsworthy as a Bresenham line drawing algorithm tutorial. TFS looks just like a "hey let's talk about how some super popular game is super awesome and post about it on a high traffic website".
Re: (Score:3, Insightful)
The physics of the teleportation are pretty boring, but the fact that you can see through the portals and have an object go halfway through a portal are unusual.
I don't care enough about programming games to RTFA, but that could be something worth talking about. Chances are it's not what they're talking about, though.
Re:WTF (Score:5, Funny)
It must be using some kind of vector mathematics for mapping acceleration onto velocity, and velocity onto position, but I'll be damned if I can figure out how they expressed that in an algorithm.
Parent
Re: (Score:3, Insightful)
Re: (Score:3, Insightful)
Re: (Score:3, Funny)
My big question (Score:5, Interesting)
If you could put a portal on a fast falling object, when it lands on you while you are standing still would you have momentum at the other of the portal or would you just poke through since the portal has the initial momentum? (IE nonplayer movement being different than player movement)
What would that say about your reference frame? Could you use that to distinguish which of two objects had "universal frame" movement? That'd be kinda neat, theoretically, but it'd be way more interesting to be able to put a portal on a crate hanging from a crane, then make the crate fall while standing under it to catapult yourself from a low position.
Re: (Score:3, Informative)
Your velocity relative to the old portal's frame of reference becomes the velocity relative to the new portal's frame of reference.
For example, if a person falls straight down into a portal on a platform moving 5 m/s, and the exit portal is on a stationary floor, the person will hurl upward out of the stationary portal with a horizontal component of 5 m/s. Which way the person goes depends on the orientations of the portals. Flip either the exit or entrance portal and you'll go the opposite direction.
Soun
Re: (Score:3, Informative)
The portals don't actually increase the velocity of what passes through them, they just redirect it. So the trick of putting two portals vertically aligned basically simulates "falling" for a much greater distance.
You would still (if in an atmosphere) reach terminal velocity rather quickly, however, so no vaporized metal (or human) explosions will happen.
Portalized (Score:3, Informative)
http://www.ogre3d.org/phpBB2/viewtopic.php?t=37376 [ogre3d.org]
He also has a blog [portalized.org] which seems quite lacking though.
Portal Physics 101 (Score:5, Interesting)
Re:Portal Physics 101 (Score:4, Interesting)
Parent
Re:Portal Physics 101 (Score:4, Insightful)
So on a slightly off topic note, does that invalidate the theory of 'wormholes' for some hypothetical FTL space travel? Surely, were it possible to create a wormhole in spacetime, you could set up a perpetual motion machine that works exactly like you describe, thus violating the second law. A nice simple thought experiment, I like it.
Parent
Re: (Score:3, Funny)
The physics is actually fake. (Score:4, Interesting)
There's a fair amount of fake physics involved. Properly, the parts of the character on one side of the portal should have the gravity and momentum of that inertial frame, and as the character passes through the portal, the new frame should begin to act on the character. But the sample code in Gamasutra treat the character as a single rigid body.
It's a neat problem to make the physics correct as the character moves though a portal. It could certainly be done, even for ragdoll characters. From a gameplay perspective, it would drive players nuts. To make the gameplay tolerable, the designers of this game added a pseudo-force that tends to align the character with the local vertical. Otherwise, characters would have execute proper parachute landing falls when moving through a gravity vector change.
Character physics almost has to be fake. Trying to drive a real car via a game pad is very difficult, and trying to drive a human body via a game pad is worse.
Re: (Score:3, Interesting)
Technically, the force of gravity should also pass through the portal, providing a smooth transition of forcesm, not a discontinuity. That would be interesting, but I think less fun. The way that the direction of gravity changes abruptly as you move through a portal is part of the charm.
They omitted what Portal actually does. (Score:4, Interesting)
Grossly Oversimplified (Score:5, Insightful)
Portal's physics go *way* beyond what the article implies.
Article basically says: it's not a simple teleport, direction of movement and momentum are preserved.
This is far too much of an oversimplification. Portal was probably a technically difficult game to code for - mostly due to collision physics. The problem is that something does not instantly teleport from one end of the portal to another. You can have an object on BOTH sides of the portal. This makes physics calculations very difficult, since you essentially have a single object of a small finite size, colliding with different objects across the room, affected differently by gravity, etc.
If I get the right gist from the developer commentary in the game, their solution was the CLONE the two sides of the portal in a mini physics-only environment and run the simulation there.
Definitely much more complex than the article.
Asteroids anyone? (Score:4, Funny)
Didn't Asteroids have prior art on this..? :)
Re: (Score:3, Interesting)
Yes no but not really. Vertical velocity is still vertical and horizontal velocity is still horizontal - just pointing in a different direction.
With Portal (and it's predecessor Narbacular Drop) you can enter a portal on the floor and pop out a portal on a wall - vertical speed seamlessly becomes horizontal speed. And that works at any combination of angles. Add to that collision detection mid-portal and you have something just a little more than what BZFlag offers.
Regarding the portals in Prey - I don't re
Re:It would have been more fun (Score:5, Funny)
multi-hundred pound canon
Omnianism has loads of holy books, but I don't think even those collected amount to several hundred pounds.
Parent
Re:am i (Score:5, Insightful)
When it was ugly, buggy, and short?
Narbuncular Drop was a great student project showing off a new idea, and I'm glad it's still available to play with. Neglecting the gameplay polish, puzzle depth, and environmental detail improvements that went into Portal is, IMO, a gross error in judgment.
You forgot to end with "get off my lawn" =)
Parent