How to reset motion with a button click in UPBGE?

I am working on a game where you can zoom in and out with the camera (which is linked to a character controller) using the mouse wheel. Would it be possible to reset the camera to the starting position by clicking the middle mouse button (i.e. undo the motion)? This is to make it more convenient when players zoom too far in or out.


One should never transform perspective by physical movements, but rather you should dynamically change it by way of changing the camera’s FOV. This can be done several ways:


Simple animate the camera’s fov OR lens value in the properties window Camera tab, thus turning it into an animation action that you can drive with numerous logic controls.





Is there a reason why this to be the case? I’m asking because moving camera around is the method I’m using currently to implement the 1st/3rd person camera :slight_smile:

I can see how adjusting only FOV can work if the character doesn’t move but what if he does or if you want to implement something like Skyrim’s camera control?

import bge
cont = bge.logic.getCurrentController()

actor = cont.owner

cam = own.scene.objects['CameraName']
if 'init_distance' not in actor:
    d2 = (actor.worldPositon-cam.worldPosition).magnitude
elif cont.sensors['MiddleMouse'].positive:
    v2 = actor.getVectTo(cam)
    p1 = actor.worldPositoin + (v2[1]*actor['init_distance'])
    cam.worldPosition = cam.worldPostion.lerp(p1,.25)

always[tap once]-----------this py
mouse middle-------------/

this assumes the middle mouse sensor is named MiddleMouse

it ‘lerps’ back to initial offset

snap_back_distance.blend (810.7 KB)

Simple answer is that LODs and sometimes OOP shaders relies on the camera’s origin location.
If you transform the camera’s view without transforming itself physically, you might well break several carefully crafted mechanics that you may or may not have implemented.

Note: I am not sure this fact still applies to frustum-culling, object-culling, and physics-culling.

Hello Blue,

I tried this but for some reason when I click the middle mouse button - the camera ends up far away from the character controller. I thought this may be due to the values but changing them seemed to have no effect. Any thoughts? Thanks.

Actually, for some reason it worked when I removed the “always” sensor. Thanks for your help!

I have a feeling that it’s at least allowable to move the camera in such a scenario, if there’s no other issues than LOD or culling could be a problem. When I zoom out the camera far behind the player character in a Skyrim-like 3rd person camera view, for example, I certainly want objects closer to the camera - not to the character - to have full LOD/physics details.

Maybe it’s something that can be chosen depending on the circumstances, I suppose. Thanks for the explanation!

1 Like