camera on rails control scheme

Blitz3D Forums/Blitz3D Programming/camera on rails control scheme

ryan scott(Posted 2005) [#1]
i don't know the name of what i'm trying to do so i'm having trouble finding clues on how to implement it

i want to make my in game camera follow my player, but on an - 'on-rails' kind of way. that is, if the player is at a given position, the camera is at x,y,z. but if the player is at a different position, camera is at x2,y2,z2.

but the player is never exactly at a given x,y,z position, he is merely closer to one of these spots than another. i want to somehow look at all the points, take the 2 he is closest to, and depending on what % he is in between them, make the camera be 'more like' that point.

wow does this make sense?

like the controls in psychonauts. man on platforms, camera moving around depending on which area he is on the platforms, to show him the next jump more clearly, reveal a hidden item, etc. pre-determined angles based on where he is on the level.

no real clue how to make this happen! does anyone know what i could look for online to make it happen?

thanks

ryan


asdfasdf(Posted 2005) [#2]
Maybe do pivots and entitydistance?


sswift(Posted 2005) [#3]
In order to do what you want, you first have to decide how you're going to define these paths for the camera. Ie, are you going to use bezier curves? Are you going to stick pivots at various locations and then have the camera linearly interpolate between them?

Once you know that, you then need to come up with a way to calculate the point on the path nearest to the player at any given time. This will be your target.

And finally, you need to move the camera towards the position of the target each frame at a speed which equals or exceeds that of the player, but along the path.

But to do that you'll need to be able to calculate a location on the path which is X distance from another point on the path, in a direction on the path towards the target point.

However, I just noticed you want to be able to move ahead of the player and set them up for the next jump.

In that case, you might not want to do the above. Or at least not do only the above.

Also, the above could present problems if you want to allow the player to choose different paths.


This might be easier to implement, but would not neccessarily give you super smooth camera movement. What I mean by that is that if your character was running up a spiral staircase around the outside of a tower and you wanted the camera to follow the action, it would be hard to get it to do that smoothly. It would move from pivot to pivot.

Anyway, place pairs of pivots in the world. Pivot A would have a radius inside which the player triggers that the camera should move towards pivot B, and stop when it gets there, or when it gets within some small distance of the target point depending on what is easier for you to code.

If the player is in the radius of more than one pivot, then you could calculate the player's location between them and then move the camera to be that same distance between its matching pivots. Or you could simply determine which is closer and then place the camera at whichever of it's pivots matches the closer one.

The camera pivots could have rotation as well as position to define the target face angle of the camera when it reaches it.

The major difficulty here would be that to get the camera to move from place to place with the player you would need your pivot zones to be large enough to encompass all the area in which the player can travel. So you would need lots of pivots, or large zones. And if you have large zones, then you'd really want to have overlapping zones and use that method I described for movign the camera to be between its own pivots to match the player's location between their pivots. This would be easy for two pivots. And maybe three. But if you end up having more than three overlapping zones it might happen that there is no location you can difinitively say matches for both player and camera since the pivots won't be matching their relative positions in space.


OJay(Posted 2005) [#4]
hm, i would try something on a per-trigger basis...

i mean:
1. define a default camera-position behind the player, which always follows the player and his field of view.
2. then make some triggers into your levels, activating special camera positions, one camera position per trigger.
3. if the player moves into or collides with a trigger move and rotate the camera smoothly to the triggers cameraposition.
4. if the player leaves the trigger, move the camera back behind the player.

sure, this may or may not work with your game, but along the information you supplied its an easy implementation...


daaan(Posted 2005) [#5]
Email me! I wrote a lib and a camera placement editor to do just this!