how to allow return to an initial view?

I want to provide user a way to return to the same view which was initially presented upon entry to game; how can I do that?

I presume I link the <home> key to some logic actuator, but I don’t know how to define the entry scene as an initial and retrievable scene. I found “Restart” under “Scene”, but I think that just restarts the game, and I suspect there’s a “better” way to return to a specified scene?

Yeah, the Set Scene setting of the Scene actuator will allow you to do just that.

ok, that works, but it works similar to what I found with “Restart”, in that my computer is either slow or the models I’m importing are maybe data intensive (?), or both, anyway lots of things, from selecting objects to initiating BGE are not happening as quickly as they do with simple objects, so I’m wondering if there is a “better” (functionally speedier) way than that to allow user to return to initial view?

And right now I’m just experimenting with a sub-set of the full model.

As long You are in the same scene You can always move everything that matters back to where it was (camera position and orientation, player position and orientation, speed etc. But it is hard and You may miss some state making the game act funny. Scenes that have already been loaded suppose tho be loaded fast (they are cashed).

LaH, did you mean via user activating the SetScene by acting from within the game, or by game creator acting in Blender to move things back?

I want to link something to the <home> key so the game user can make everything automagically be moved back to the same as it was when the game was entered.
(That’s because it’s not really a game, but rather a model viewer with rotations etc).

And as far as the scene being cached, it makes sense that it would be done like that, but it just took 10 seconds to reset the initial scene via SetScene (inclucding black screen, "Blender…(not responding)), which is making me think my computer is just too slow.

Okay, then you might want to try a Python script to loop through all objects and return them to their original positions and rotations. You’ll have to have a script that, when the game begins, it stores the positions and rotations of all objects, and when you need to press the Home key, you’ll load those positions and rotations.

Solar: ok, something like that occured to me, though I don’t yet know how to do it.

For now, all the user movements are restricted to rotating two sets of 5 objects apiece around an empty mesh, by rotating the empty mesh (since it’s their parent); so, if there were a way to store the original orientation of the empty mesh, then all I’d have to do would be return that empty mesh to its original position & rotation, and all else would follow, right?

But I don’t know how to write a script to do that.

I’ll google now, but if anyone has any examples etc, that’d help a lot!

Yes, that’s what you’d have to do. The script itself would be fairly easy to implement, probably within 20 lines of code or so (a very short script).

ok, so, looks like I’d need TWO scripts, one to store the rotation/orientation properties of the emptymesh on BGE entry,
and one to be activated by <home> key to return emptymesh & associated objects to that original condition, right?

Now, for a complete noob trying to write those scripts:

Are there some scripts which come CLOSE to what I need that I could study/ammend?

GENERAL SCRIPT WRITING QUESTIONS:

  1. probably use text editor in blender, but do I choose ADD new or OPEN new?
  2. how and to where do I SAVE script when finished?
  3. are there GENERAL things I need to do in a script BEFORE I tell it to do the specific things the script is for? (& if so what things?)

SPECIFIC QUESTION, RE SAVING INITIAL CONDITIONS:

  1. how do I GET the initial orientation properties of the emptymesh, and then how do I SAVE them such that the other script can retrieve them?

SPECIFIC QUESTION REGARDING RE-SETTING INITIAL CONDITIONS:

  1. how do I retrieve the stored initial conditions, and then how do I command re-set to those ini conditions?

I do see that there’s a Python Controller, so I at least have a hint as to how to activate the re-set script, but I don’t see any way to do an “activate script on entry” action to activate the “get original conditions” script.
[edit] might “activate script on entry” be done with an "always"sensor with “tap” parameter set?

Well, you could put them into a single script… Also, I would personally recommend using an external text editor like Notepad++ if you’re going to get deeper with Python, though for a light, single script the BGE text editor works okay.

  1. You should choose Add New.

  2. You don’t need to save the script - it’ll go with the blend file.

  3. The basics are basically to import the logic module,

  4. You can get the initial orientation by just copying the variable.

You know what, I’ll throw together an example file for you.

EDIT: Here it is. You can just add objects to the script to copy their rotations too, though once you get more than one or two, you probably should use a list.

Oh, and this is Blender 2.5, by the way. Are you using 2.49? If you are, I included a 2.49 version inside the blend file - you can just copy the logic brick layout and 2.49 script (which I didn’t test, though).

RotationTest.blend (362 KB)

heh heh, quicker to DO it than try to DESCRIBE it, eh! and THANKS!! I’ll give it a try, and yes, 2.49.

[edit] it won’t load, error says “file incomplete”.

Sorry, that’s a 2.5 file. You can load it in 2.5 to see how it works, and copy the 2.49 script from there, as well.

Could you please send the 2.49 script itself?

and I think I have a vague understanding of what you meant that one script is all that’s necessary, namely by testing if the script has ever run before; if not run before, then gets the orientation data and somehow saves it and does nothing else; if has run before, doesn’t get current data, retrieves and resets to previous data, right?

If so, then script has to run from two activations, one from always sensor with Tap set (for startup?), and another from key <home>, right?

Yeah, that’s right. The Always sensor actually can be just set to 0 pulse with no true or false level triggering, and the home key will activate the script. This should work:


Here’s the script.
http://misc.cgcookie.netdna-cdn.com//pencil.png

ok, haven’t got it to work yet, changed homekey variable name to ReturnToInit as I already had labeled the logic brick to that
and removed empty lines from script.
here’s screenshot:


here’s error:

Blender Game Engine Started
Python script error from controller “ResetInit#CONTR#5”:
Traceback (most recent call last):
File “ResetInit”, line 7, in <module>
KeyError: “CList[key]: ‘‘OBRotator’’ key not in list”
Python script error from controller “ResetInit#CONTR#5”:
Traceback (most recent call last):
File “ResetInit”, line 9, in <module>
KeyError: ‘value = gameOb[key]: KX_GameObject, key “oricopy” does not exist’
Blender Game Engine Finished

Have I done something wrong?

No - in my example, the Rotator object (OBRotator) was the object that I resetted the orientation of. You need to replace ‘OBRotator’ with the name of the object in the scene that you want to reset.

ok, I replaced “OBRoatator” with “OBEmptyMesh”, and I still get 2 failures, one on entry and one on press <home> key:

Blender Game Engine Started
this is error on entry to BGE:
Python script error from controller “ResetInit#CONTR#5”:
Traceback (most recent call last):
File “ResetInit”, line 7, in <module>
AttributeError: ‘list’ object has no attribute ‘copy’

and this is error on press <home>key:
Python script error from controller “ResetInit#CONTR#5”:
Traceback (most recent call last):
File “ResetInit”, line 9, in <module>
KeyError: ‘value = gameOb[key]: KX_GameObject, key “oricopy” does not exist’

and here’s screenshot:


Can you tell whatever it is I’m doing wrong, or do you need any more info?

Oh, I see. The prolbme is that you can’t use the copy() function (that’s in 2.5, not 2.49). To fix this, change the 7th line (obj[‘oricopy’]) to

obj[‘oricopy’] = sce.objects[‘OBEmptyMesh’].orientation[:]

That should work.

OK, yes, that works now, thanks!

If all you are doing is rotating the model a Track To actuator can return it to it’s initial default orientation without you having to know or script it’s original or current orientation. In other words at start have the model already aligned to another empty. Thereafter whenever you like hit a key to track it back to that empty. Likewise if you are rotating the camera.

If you are translating the camera or the model, or changing the lens angle of the camera you’d need to do a little simple scripting.