Camera question ?

Hi all, is it possible to block the camera in Z axis when is vertex parenting with the player ?
In alternative is it a possibility via script to make the camera follow the player without move in Z axis ?

Thanks in advance :o

  1. Yes. I’d do it with Python. Get the initial z position of the camera and then set it to that, every frame.

try ADD OBJECT CONSTRAINTS > COPY LOCATION > uncheck Z

Ok, thanks, I try both :wink:

Guramarx, it doesn’t work with Obj constrain, I’ll try with script later, thanks

properties panel -> hit the tab with the cube icon -> transform locks-> lock z axis.
no idea if it works ingame, but worth a try

ah see your looking for a script as well, ok ill make you one.

here you go, put this script on any object you like with an always(true pulse)->python

from bge import logic

def let_cam_follow_player(cont):
    
    own = cont.owner
    
    player = own.scene.objects['player']
    camera = own.scene.objects['camera']
    
    camera.worldPosition.x = player.worldPosition.x
    camera.worldPosition.y = player.worldPosition.y
    #camera.worldPosition.z = player.worldPosition.z

oh and dont forget to change the names of you objects in the script. Do you know python a bit? due to now it gets exactly above the player. add a + offset_number behind te player.worldPosition to create a distance between them.

Thanks cotax, works well, I know a bit of python, I make the script a bit well :smiley:

import bge

cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
own = cont.owner

player = own.scene.objects[‘player’]
camera = own.scene.objects[‘camera’]

camera.worldPosition.x = player.worldPosition.x
camera.worldPosition.y = player.worldPosition.y - 18
camera.worldPosition.z = camera.worldPosition.z

the camera take the Z position it self for avoid the jump of the player :smiley:

Thanks a lot again, I can continue with my game :wink: