I have written a script in python that successfully saves and loads the position and rotation of my player cube and camera for use between scene transitions. However, something is going wrong with the minimum and maximum rotation values of the mouse look actuator. I have a feeling that I should be adjusting those values in python at the same time I change the camera rotation from the save, but I'm really hung up on this.

Here is the code I wrote:

import bge
from bge import logic as g

def save():
    s = g.getCurrentScene()
    pos = s.objects["player"].position
    rotP = s.objects["player"].worldOrientation
    rotC = s.objects["player_camera"].localOrientation

    g.globalDict["pos"] = [pos.x, pos.y, pos.z]
    g.globalDict["rotP"] = rotP.to_euler()

    g.globalDict["rotC"] = rotC.to_euler()


def load():
    s = g.getCurrentScene()
    s.objects["player"].position = g.globalDict["pos"]
    s.objects["player"].worldOrientation = g.globalDict["rotP"]
    s.objects["player_camera"].localOrientation = g.globalDict["rotC"]


It's as if these values are being changed by something: enter image description here

Thank you for your time. I'm really stuck on this.


1 Answer 1


You should use the actuator.angle attribute, or actuator.angle[0] if only the X value is needed. Here's a example script I made and test file attached here.

import bge

from bge.logic import expandPath
from ast import literal_eval

def main(cont):

    # Objects
    own = cont.owner

    # Sensors
    S = cont.sensors['S']
    L = cont.sensors['L']

    # Actuators
    MLook = own.actuators['MLook']

    # Properties
    path = expandPath('//save.txt')

    data = {
        'pos' : list(own.worldPosition),
        'rot' : list(own.localOrientation.to_euler()),
        'mouse' : MLook.angle

    ### PROCESSING ###
    # Save
    if S.positive:

        with open(path, 'w') as opened_file:
            print('Saved data to', opened_file.name)

    # Load  
    if L.positive:

            with open(path, 'r') as opened_file:
                data = literal_eval(opened_file.read())
                print('Saved data to', opened_file.name)

            # Set obj data
            own.worldPosition = data['pos']
            own.localOrientation = data['rot']
            MLook.angle = data['mouse']

            print('Cant load saved file')

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .