BGE - Camera World Position - Smooth Transition Question

Hi peeps!

I’ve been messing around with Blender quite a lot trying to set up a camera that follows the player with it’s rotation, but the position is limited to either X, Y and Z depending on what area the player is in (in this case, corridors).

I’ve managed to get the thing I wanted done (limiting camera’s movement to specific axis), but the transition between areas causes the camera to stutter, it just jumps straight to it’s new position very unnaturally. So my question is, how would I get the camera move into it’s new position smoothly?

I’ve tried adding or subtracting values, which did indeed make the transition smoother, but it made the camera constantly shake like out of control even when just standing idle in one corridor…

if cam_y > -18.0:
cam.worldPosition.y = cam.worldPosition.y - 0.1

if cam_y < -18.0: cam.worldPosition.y = cam.worldPosition.y + 0.1

So this one above did not do the trick… I wonder if anyone could help me out? I’m attaching a BLEND FILE to this post, It’s very small so if you have 2 minutes, u might be able to literally save my life.

Thank you ever so much for your time in advance!


slow parent

Hey Monster, thanks for the info, that’s exactly what I stumbled upon (by accident) and it was indeed smooth, but:

My camera is not actually parented to the player?

I’m using the Camera Actuator. It’s constantly looking at an Empty, right in front of the “player” and has to have a min/max distance from it, being only able to move on 1 of 3 axis.

I’ve tried slow parenting the camera to another empty, and then limiting the position of the empty using the same Python code. I added a track to, to the empty aswell so that it looks at the player. It was a nasty naaasty result. The empty was beamed right below, on top of the player. I didn’t expect it to work that way anyway, but was worth a shot!

So this might be a bit of a silly question, but slow parenting does seem to be the way to go, so, using the camera actuator, would I be able to get some slow parenting done?

I’ll be honest, I’m fairly new to blender, and ezpecially python. When I figured out that little piece of code I was so proud haha… so yeah, that’s why I’m asking for help, I’d like to figure it out myself but I’ve run out of ideas.

Once again, thanks for the help!

You can change the timeOffset via Python to “virtually” switch off(and on) slow parent. This way you apply the logic you have at your camera now -> to an empty and slow parent the camera to the empty. When you discover the situation when you need smooth, you can set a timeOffset > 0. When you want to switch it off -> timeoffset = 0.

You seem to do your own motion to the camera. Rather than correcting the position with constant steps you could perform steps with a size dependent on the distance to the target position/range.

e.g. position += distanceToTarget/ratio

It will still move pretty fast as more distance there is, but it is relative smooth.
Alternative, you can calculate a speed. This means, you increase/decrease the stepsize dependent on the distance to the target. This prevents a fast start, when you set a target far away.

you can use physics, to move the camera…

I don’t have my pc on at the moment, but one of my camera hosts, is attached to a rigid body ghost that uses force and torque, so its pretty smooth, you can also reduce the strength of the effect and apply movement using force and torque impulses for manual control.

you can use physics, to move the camera…

You can do that but you will have to parent the camera to a ghost cube as he said, as the camera has no mesh, and youll have to balance out your gravity, by applying a constant upward force to the cube, or making it weigh nothing(which the latter is not a good idea, as movving something around with no mass can be very fickle).

The camera actuator actually works pretty well. You can use python to change the min/max/distance/smoothness values as you want rather than changing actual distance and orientations to the camera itself. I beleive that is what Monster is saying. My orbiting camera uses the actuator, turns the smooth to off when I click to orbit around, then resets the smooth when I release the click. It works really well. For zooming with the mouse wheel, I just change the min/max distance values of the actuator with python as well when I roll the wheel.

In my experience stuttering is caused when it tries to move, but moves too far, and has to back up to correct itself(resets position). So it could be moving too far, OR too fast. I cant check the blend cause im not at home so I cant check your setup, but if you have it moving by a constant, Use a Fraction of the distance to your target(or threshold from target), and catch it when it hits the threshold. This gives you that nice slow to a stop effect also

You dont HAVE to use the actuator. Theres a ton of ways to do it. Just keep working at it.

import bge
from mathutils import Vector
cont = bge.logic.getCurrentController()
own = cont.owner
if 'init' not in own:
    scene = bge.logic.getCurrentScene()

    own['init']= scene.objects['Target']

    distance = own.getDistanceTo(target)
    vec = own.getVectTo(target)[1]
    force = vec * X1*distance
    m1  = own.worldOrientation.copy()
    m2  = target.worldOrientation
    dif = Vector((m2 * m1.inverted()).to_euler())
    x = dif.magnitude
    if x &gt; 1:
    force1 = own['Force']*own.mass

    own.applyTorque(dif * force1*x, 0)
    force.z = force.z+own.mass*9.8
    own.applyForce(force*distance, 0)

properties in physical object

‘X1’ - Force used to move camera
‘Force’ - strength of torque applied

always 1 tap---------------ForceMove

change the value of target to the item you want it to track

(works for much more than cameras)

try high numbers because it is heavily dampened

Hey guys,

First of all, big shout goes out to every single one of you who responded, I’ve indeed managed to get the solution, Monster, I’d have never thought I could use the camera actuator on anything other than a camera, so there it goes, slow parenting and a little messing with values did the trick. I’d say It’s spot on what I wanted! :slight_smile:

Feels like getting somewhere! (SH Item Pickup sound in there ONLY for a joke… not planning to use it really)

The camera in BGE/Standalone runs perfect, the lag in the vid is basically my old pc + blender + screen record… need a better machine :stuck_out_tongue:

Thanks again guys!