Skip to main content
gamedev.net
🔒 Locked

Camera Spline Problem

Started by gameplayprogammer Oct 12, 2006 at 5:25 PM 1 replies 900+ views
Original Post
gameplayprogammer
gameplayprogammer
I am trying to get a camera to travel along a spline while keeping a moving target a distance away from the camera. The target is a 100m sprinter and is running in a straight line along a track(lets say the track runs from 1 to 100 on the x axis). The camera spline runs along the left side of the track for about 50 metres then loops/bends over the track and runs along the right side for the remaining distance. I find an ideal camera position by finding a point along the x axis that is 30 degrees to the left of the sprinter's current position, then try to speed up or slow down along the spline towards that point(so the x value of the camera position equals the x value of the ideal camera position, z values will be different) Problem is with the loop\bend, the sprinter catches up and passes the camera, also the camera makes big jumps along the spline during the bend so the movement is not as smooth as on the straights. I think it is because the spline is running more along the z and y axes during the bend. Another problem is i can only move faster or slower(or stop) along the spline, i can't move to a specific x,y,z on the spline(because of the function i am using) Anyone know a way round this or a suggestion?
Palidine
Palidine
With the constraints you've specified it seems like the solution is to re-place the spline in a position that "works" with your camera logic.

Something else you might want to add, is that it seems you are "popping" the camera along the spline. What you want to do is give it a max velocity and push it along the spline instead. If the "perfect" place is not reachable this frame, just move as close as you can get. You can have the camera always pointing at the right spot so the sprinter doesn't go out of frame. This way it's the designers responsibility to place the spline "correctly" to get good looking results.

-me
gameplayprogammer
gameplayprogammer

thanks for your reply, got me thinking alittle about my code, i was doing something like this to move the camera along the spline.

factor=distanceCameraTravelledSinceLastFrame/distanceTargetTravelledSinceLastFrame;
nextFrameSplineStep=factor*thisFrameSplineStep;

but i was calculating the distances for both the target and camera only along the x axis, hence my camera slowed down along the bend when it was doing most its movement along the z axis and i was not taking this into account.

i should have been doing this

lastFrameCameraPosition - thisFrameCameraPosition = vectorFromLastToThisCameraPosition;

lastFrameTargetPosition - thisFrameTargetPosition = vectorFromLastToThisTargetPosition;

get the length of these two vectors will give me an accurate distance travelled.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.