Search In
• More options...
Find results that contain...
Find results in...

# Smooth camera transitions

## Recommended Posts

Is there a way to interpolate camera smoothly using script hook?

Lets say the goal is to make a custom orbiting camera around your player character/current vehicle that you can control with a mouse.

AttachTo works nice when the character is moving, but it lags if you change offset.

Changing position of a detached camera to follow your character also lags.

##### Share on other sites

If you're wanting a camera interpolation, I'd suggest this

CAM::SET_CAM_ACTIVE_WITH_INTERP

It involves creating a second camera where you want the destination

##### Share on other sites

• 1 month later...

The way I did it in my camera mod was using a method I have used for years... literally 30 years. When you move the camera, that creates a desired rotation position. You take the distance between the current rotation and subtract that from the desired rotation, that leaves you the difference. You then divide that difference by maybe 10 or 20, and then add that value to the current rotation and store it for next time round. That will accelerate the camera towards the desired rotation position and will naturally slow down as the distance between the two decreases. I use it a lot for scrolling things into and out of view, like panels etc...

If you want to keep a lid on the maximum value, then just do a Math.Min(CameraMoveValue, .1f) or something similar. That means that it will take the smallest value of either what you have calculated, or .1f. So the .1f becomes the maximum amount the camera can move in a single move-step.

I use the same technique in my mod for two situations, one is an orbiting cam that is always trying to maintain a fixed position relative to the player. The other is with a rising or falling camera that is moving towards a fixed point. It doesn't cater for acceleration though, so if you want that, then you'll need to implement an acceleration function into it.

Here's the short piece of code I use for the orbiting camera function. GetShortestAngle and Wrap are two separate functions for dealing with angles. The acceleration is not clamped in this function.

`if (TrackTargetRotation){	float _difference = GetShortestAngle(OrbitRotationAngle, Rotation.Z);	float _inertialModifier = _difference / 20;	float _newOrbitRotation = Wrap(OrbitRotationAngle + _inertialModifier, -180, 180);	OrbitRotationAngle = _newOrbitRotation;}`

For my falling camera, which is clamped, I use this... the rising one uses a slightly different clamp value but it's essentially the same thing.

`case "Falling":	_riseVal = Position.Z - RiseFallTargetHeight;	_riseAmount = Math.Min(_riseVal, .7f);	Position.Z -= _riseAmount * fTimeModifier;	break;`

It's quick, easy, easily customisable and avoids the need of setting up multiple cameras, if you only want something simple. If you want true interpolation though, what unknown modder posted is the best bet.

##### Share on other sites

In CSHV.NET you could use cam.interpTo() with predefined interpolation lengths and Wait() times between commands.

##### Share on other sites

• 7 months later...

If you're wanting a camera interpolation, I'd suggest this

CAM::SET_CAM_ACTIVE_WITH_INTERP

It involves creating a second camera where you want the destination

Works fine for me.

1. Create 1st camera and place it

2. Create 2nd camera and place it

3. Activate 1st camera and then use SET_CAM_ACTIVE_WITH_INTERP to 2nd cam from 1st. Do not forget to deactivate 1st camera

4. ?????

5. PROFIT!!!!

## Create an account

Register a new account

×