# 'Channels' and limited movement.

Hi guys,

I’m trying to make a movement system that is basically a set of rails. The player can only move along the rails and only has one key control - move. The idea is the player will move along rail in the direction they are looking, so if they come to a junction they can move off down it if they look that way. The game is in 3D corridors but here’s a plan view to make myself clear. Red dot is the player, blue triangle their view angle.

The camera attached to the player is a full 3d freelook camera, so I’ve got to make it some how interpret an area that counts as ‘the way the player is looking’ so it knows to move that way if Move is pressed. So even if the player is looking about 45 degrees ‘downwards’ it still moves forward if you see what I mean.

Anyone got any ideas as to the best approach to this? Code sample to get me started would be hugely appreciated!

I think you find dot product quite useful for this.

I wont explain the whole concept but to summarize, the dot product is bigger for vectors which point in similar directions.

if A and B are the same, then A.B = 1
if A and B are perpendicular (at right angles), then A.B = 0
if A and B are in opposite directions, then A.B = -1.

By taking the dot product of the direction of the camera and the current rail(s) the player is on, then you can determine which rail to move along in which direction.

That seems like it’ll be exactly what I need, if I can work out how to get started Cheers.