"Spawn" character at specific location in scene

Note: This problem has been resolved, the solution is at the bottom of the page.
I have a question that I feel is not really covered that much. First I want to explain the layout of the scenes which make up this simple example.

There is a hallway with the player’s starting point near the west wall. On the north-east side is a door, for sake of the example lets call it door A. Each time I start the scene my character will appear at the Start point. This is normal. Door A has a link to scene “room 2”, which also has a door leading back to the first scene “room 1”. If my character goes through door A it will appear where I placed it in “room 2” scene, which is right in front of the doorway. If my character goes through the doorway in “room 2” scene, it will appear at the start point in “room 1” scene, rather than appearing as if it walked through the doorway and was standing in front of Door A in “room 1” scene.

As in real life, if you walk through a door you will be on the other side of the doorway as opposed to instantly being on the other side of the room. :confused:

The solution to this may require python programming, but if it is possible then I would be able to follow along. Thanks!

Attachments


Hi there!

Well… You can load and unload objects and create a corridor to manage an intermediate state between loaded objects. Something like: if you are in one half of the corridor, then load object (room) “B” if you hit the other half, remove object “B” and reload “A”.

Please take a look how “Yo Frankie” loads different scenarios: it is a link between many .blend files, that’s another approach :wink:

I didn’t studied the new culling system, so no clue about how it works, but i think you need to take a look at this, it might interest you.

http://wiki.blender.org/index.php/Dev:Ref/Release_Notes/2.49/Game_Engine#Performance

This sort of thing is pretty easy to program in C++ 2D games but when it comes to Blender and python it’s a whole new language. Harvest Moon game for example, you start out on your farm land and walk into your house and you are in the doorway. You leave the house and programming puts your character at the certain location which is outside the house door. But when you go to town and back to your farm, programming puts your character at the path to the town instead of at the door to your house.

I saw the getScreenPosition(obj) code, but that only gets the position of the object, it doesn’t set the position. I need to find something that goes like putPlayer(2, 3, 4). That’s not a real code but just an example. It would put the “player” object at the coordinates X, Y, Z listed.

This came up recently,
http://blenderartists.org/forum/showthread.php?t=164864

This contains a simple demo of portals between scenes/blend files, and positions in the level.

you can use setPosition(1,3,2). that’s the old code and will be depricated, but the terminal will tell you the new code.

Thanks for the info, I checked the level portals Apricot project page too. It didn’t seem to have exactly what I was looking for though. Is there any way to press a key (spacebar) and have the cube move from one location immediately to another, say, across the room or behind a wall that the player couldn’t walk past? That is, without using empties; but python.

mcguinnessdr, I found a related setPosition code. Toomai wrote it somewhere else in the forums. It worked very well, I changed the XYZ values to in front of the doorway. Now is there any other code to set the rotation as well? I’ve tried setRotation just to see if that would work, but it was only a guess. Here’s the setPosition code that I found.

cont = GameLogic.getCurrentController()
own = cont.getOwner()
teleport = cont.getSensor("Teleport") #you need a sensor linked to the Python controller that's called "Teleport"
 
if teleport.isPositive(): #if the teleport sensor is activated
  own.setPosition([1.68, 1.68, 1.18])
  own.setRotation([0, 0, -180])
 #these numbers are the xyz locations of where the character will end up, change them as neccessary

I have this for my game here:
http://blenderartists.org/forum/showthread.php?t=158651
My friend made this, it works really really well, for example:

You can have it so your running through a forest of field and when anywhere you touich the plane or cube, it teleports you the the next scene to a relitive location, not a certain place litterly wher eyou would end up if you where to take a path… It works like if the scene is longer and if you make it well, you won’t have the notice the scene change :wink: Hope this helps!

That works quite nicely, Linkxgl. Thanks for the reference! This method seems similar to the Portals in the Game Engine on Blender artists. ( http://www.blendernation.com/portals-in-game-engine/ ) Only without the video texture. But it still works great. I’ll use it if I make a side scrolling game for scene to scene movements. Thanks again, cheers! :wink:

Update: I added in setOrientation([]) code which fixes the rotation setting. I’m not quite sure how 9.5 = -180 Z turned object though. Here’s the code, you’ll see what I mean by 9.5. I’ll also attach the .blend file. THANKS A LOT FOR ALL THE HELP, EVERYONE!!!

cont = GameLogic.getCurrentController()
own = cont.getOwner()
teleport = cont.getSensor("Teleport") #you need a sensor linked to the Python controller that's called "Teleport"
 
if teleport.isPositive(): #if the teleport sensor is activated
  own.setPosition([1.68, 1.68, 1.18])#these numbers are the xyz locations of where the character will end up, change them as necessary
  own.setOrientation([0,0, 9.5]) 

Question: I put in the 9.5 Z number and the character rotated roughly to -180 Z degrees. How does 9.5 equal -180?

Attachments

Set Position and Rotation test.blend (202 KB)