Game Development Reference
In-Depth Information
// Set the initial camera matrix
ComputeMatrix()
end
function Update( float deltaTime)
// First calculate the ideal position
Vector3 idealPosition = target . position -
target . forward * hDist
+ target . up * vDist
// Calculate the vector FROM ideal TO actual
Vector3 displacement = actualPosition -
idealPosition
// Compute the acceleration of the spring,
and then integrate
Vector3 springAccel = (- springConstant * dis-
placement ) -
( dampConstant * velo-
city )
velocity += springAccel * deltaTime
actualPosition += velocity * deltaTime
// Update camera matrix
ComputeMatrix()
end
end
The biggest advantage of a spring camera is that when the target object turns, the
camera will have a bit of a delay before it starts turning as well. This results in a
sense of turning that's much more aesthetically pleasing than a basic follow cam-
era. And even though the spring camera looks much better than the basic follow
camera, it does not require too many additional calculations.
Search WWH ::




Custom Search