x


Rail Platformer Collision Detection

I'm interested in making a really dynamic and flexible platformer on rails. The world is 3D, but the player is constrained to a 2D rail that curves around the 3D environment, with movement constrained to the usual XY along that rail. (For an example of what I mean, see Tomba 2 or this part of Klonoa.)

I've already developed a "rail system". Basically, it connects a number of nodes together into one long spline, and objects can "connect" themselves to the rail to move along it. Their X progress along the rail is defined by an interpolation value ranging from 0.0 (the first node) to 1.0 (the next node). Traditional Y space movement is defined using continuous normals defined at each node.

The issue is collision detection. It would be nice if I could use CharacterController.Move() to do all that jazz for me, but it assumes my movement is defined by directional vectors (which, to be fair, is true for 99% of applications). If I use Move(), it would only calculate movement in a straight direction tangent to the rail; however, the rail can twist and curve, so movement has to also be along the curve (defined as a value between 0.0 and 1.0).

As a visual aid, consider the following image (borrowed from Google...):

Spline Graph

The spline represents a top-down view of how I might have the 2D rail weave through a 3D environment, with nodes at t=t0, t=t1, etc. CharacterController.Move() requires a Vector3 to be passed to it that represents a straight, directional movement of a CharacterController object. However, the best I can pass to it on my rail system is a Vector3 tangent to the spline at that point, as can be seen by tng0, tng1, etc. Obviously, these tangent values don't represent an object's actual movement along the rail and could result in a false collision if a collider exists just off the rail, or a missed collision if a collider exists on the rail and the tangent misses it. (Not to mention that the returned Vector3 resulting position would be inaccurate and off the rail.)

Is there a good solution for this? I'm thinking it's going to have to involve me doing collision detection and, upon detecting a collision, move a game object backwards along the rail and its Y velocity until it no longer detects a collision. These "rewinds" will have to be of a specific step size, with a larger step being less resource intensive and a smaller step being more accurate.

Another visual example of the problem:

Rail Example

Sound about right? Any advice?

more ▼

asked Oct 10 '12 at 10:35 PM

LoftyTheMetroid gravatar image

LoftyTheMetroid
1 1 2

If by normal colliders you mean what I described in the last paragraph, yes, although I'm not sure it's the best solution. I just don't know what magic is going on behind CharacterController.Move(); if I could see it's implementation, I could probably replicate it fairly easily on my rail system. I'm just afraid of trying to recreate collision detection and not understanding (and thus implementing) all the necessary details that go along with it.

Oct 11 '12 at 11:33 PM LoftyTheMetroid

can you clarify? Are you saying that collision detection might basically kick you back out of the map because it will move you back as it were but your line backwards is basically a curve so you want to make sure it doesn't move you in those ways?

Or that basically move forward isn't forward because it tries to draw a straight line to connect you to the point you want to go but that doesnt work because forward 10 feet might actually basically be a C shape that takes you out and ends up a foot above you not just 10 feet out?

Oct 12 '12 at 12:56 AM sparkzbarca

just to note what im thinking in my head im guessing waypoints might be the easiest system to solve it. but i'm not sure if your problem is what I think it is. :P

Oct 12 '12 at 01:02 AM sparkzbarca

CRAP, why does the "Delete" button have to be so small and so close to the "Edit" button?!?!

To summarize: I think your second paragraph describes my issue more accurately, although there is also a problem with returning an accurate post-collision position from CharacterController.Move() since Move() doesn't consider the rail system and won't necessarily return a position located on the rail.

I don't think waypoints would be useful here, although I'm not sure I'm thinking of the same thing you are. Could you elaborate? The nodes of my rail system define a strict path that attached objects cannot deviate from.

I updated the question with an explanatory paragraph and image, hopefully that helps. I also recommend looking at the Tomba 2 video I linked to get a good idea of what I mean by "2D Platformer Gameplay on a Rail in a 3D environment".

Oct 12 '12 at 05:02 AM LoftyTheMetroid
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

So yea every curve is really a series of straight lines. All you need to do is ensure that the steps are small enough you don't ever go off the rails.

I think by creating a list of waypoints and simply iterating through the list you can get directions easier and safer and fix any issues quickly with some map editing.

whenever you reach a waypoint that is considered your location for the purposes of choosing your next movement vector.

for example you pass the third waypoint and would like to go on to the next one so your position is called waypoint 3. if you press to go back you would move towards waypoint 3.

if you press to go forward you move towards waypoint 4.

you said this is a unique problem but really the rails problem is seen in any racing game. your racing along a narrow 3D path. It's been solved many times normally through pathfinding, and with racing that is often waypoint based.

You may wish to check out the roads/path tool in the asset store. it's free. There are several paid ones as well.

Best of luck.

more ▼

answered Oct 12 '12 at 05:31 AM

sparkzbarca gravatar image

sparkzbarca
3.2k 2 6 18

That's actually the exact solution I used in an older StarFox-esque rail flyer demo I made awhile back (you can see it on my website, you just have to click "Play The Flight of Hermes!" on my portfolio page here: http://www.tayloryust.com/#!Odyssey Suite/c1bph [copy the whole link, space and all...])

That works for racing games and the like because the playable game space isn't exactly a strict path; there's an added dimension of space where you can move laterally along the track, and the actual game space is defined by the environment. The waypoints act more as "guidelines" through the space.

The problem is that, for a precise platformer, I can't really approximate movements like that. It'd be either very easy to break, or it'd be too limiting to the design. With the Hermes game I linked above, I ran into issues where errors would compound and I couldn't accurately predict the character's flight path, and he would even sometimes go off the rail path as you said. (Try getting a speed boost through the cloud section...)

My rail system was designed as a solution to the issues I encountered with waypoints for games that need strict paths. Unfortunately, not using straight, directional movement vectors in my design complicates collisions, hence my problem...

Oct 12 '12 at 05:51 AM LoftyTheMetroid
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x186
x94
x12

asked: Oct 10 '12 at 10:35 PM

Seen: 474 times

Last Updated: Oct 15 '12 at 06:46 AM