Fixing 3rd person cam

how can I make an object rotate to make his y-axis the same of another when press a key in blender game engine
sorry for my bad English

1 Like

copy the orientation

obj1 = own
obj2 = own.scene.objects['object2']

if button is pressed:
    obj2.worldOrientation.col[2] = obj1.worldOrientation.col[2].copy()
1 Like

i am new to blender what do with this
and thank you

well it’s just a demo piece of code, you need to understand python.

Anyway, if your new then your better of grabbing a ready to go setup, i got one here:

1 Like

how to use this code i have already set the wasd movement

asdasdasd.blend (480.0 KB)

1 Like

is this work in upbge 0.2.5 is no for me

Ah, next time use the tag in the title, i assumed no tag = BGE

For UPBGE 0.2.5 nothing is compattible anymore, so you can recreate the exact.blend in upbge and it will work.

or simply open upbge, file->append, then append all objects from my blend.

1 Like

ok thanks man you helped me

1 Like

ok so here you can find my project can you fix it for me what i want is to make the SPONG cube rotate in z-axis only when i press z or s or d or q like the empty cam

Your better off using my setup, just put your armature and spong mesh into it.
I’m not gonna create another 3rd person script.

the below script works but not how you want it to be, that is due to the camera (different axis’s).
see how i defined the keyboard sensor?

anyway just use my .blend, the cube is the player box, just append your spongs and armature, then parent it to the box. when ingame press K to change your controls.

def z(cont):
    own = cont.owner
    obj1 = own.scene.objects['cam']
    obj2 = own.scene.objects['SPONG']
    z_button = cont.sensors['Keyboard.001']

    if z_button.positive:
        obj2.worldOrientation.col[2] = obj1.worldOrientation.col[2].copy()
1 Like

your .blend not work with upbge 0.2.5 but work with 0.3 but it’s not stable

do you mean what i want
if ok can you do that using only game logic

download the one for upbge, it works.
for 0.3.0 there is a setting that needs to be changed else the camera keeps drifting

I’m sorry but you need someone else for that, i am not that good with bricks

1 Like

ok, thank you I used your 3rd person .blend

1 Like