Making the player spawn at a different location after going between scenes.
keflyn
Member Posts: 29
Hello,
Sorry if this has been asked before, I can't find the search function on this website.
In my game the player can go in and out of buildings, I've got it so they are able to do so but when they come out of a building, they spawn at the start of the game again. I would like to know how to make it so the players spawns just outside the building they just entered?
Thanks in advance.
Sorry if this has been asked before, I can't find the search function on this website.
In my game the player can go in and out of buildings, I've got it so they are able to do so but when they come out of a building, they spawn at the start of the game again. I would like to know how to make it so the players spawns just outside the building they just entered?
Thanks in advance.
Comments
When your enter a building save the players x and y location to the relevant last attribute.
When reentering the scene, have the player spawn at lastX and lastY values.
Something like that should work!
Thanks.
You will need to have a rule in your player which just before the scene changes saves the values.
use a change attribute behaviour and save player.x to lastX and player.y to lastY
If your in the player actor it will be self.x and self.y that need saving.
Got two attributes like you suggest, then inside the player actor I have this;
Rule
Actor receives event - overlaps or collides - actor of type - jump-2-apartment
- Change attribute - self.positionX to game.lastX
- Change attribute - self.positionY to game.lastY
Thanks again.
In your spawn rule, spawn at lastX and lastY.
whenever you want to change scenes-
change attribute lastx to self position x
change attribute lasty to self poision y
then a timer after 0.1 second run to completion checked,
change scene
then at the start of the scene when you go back to it,
change attribute self position x to last x
change attribute self position y to last y
I have 3 actors, my playable character, an actor that sends my character to the next level(jump-2-apartment) and another actor that sends them back to the first level. (jump-2-street)
in my player I have this rule set up;
Actor receives event - overlaps or collides - actor of type - jump-2-
apartment
change attribute
change attribute game.lastx to self.positionx
change attribute game.lasty to self.positiony
timer every 0.1second
Go to Scene - "Apartment"
Actor receives event - overlaps or collides - actor of type - jump-2-street
change attribute
change attribute self.positionx to game.lastx
change attribute self.positiony to game.lasty
Go to Scene - "Apartment-street"
*Note* All behavior is in player actor non in the scene change actors.
That is all the behavior for the scene changes, where have I gone wrong?
Thanks again and sorry for being so stupid with this.
What you need is, in your playable actor on the street scene, a rule which as soon as it loads changes its self.x and self.y position to lastx and lastY.
The only thing is, at the start of a new game you want the player to start in the starting point, not the lastX and lastY. To do this, have a rule in your start button on the titlescreen which changes lastX and lastY to the position you want the player to start.
Also, since my character is spawning at the actor that sends it to the next scene, my scene just changes instantly when going back to the starting scene?
on top of that problem, there is now a problem with my light, it's not following with my player up and down anymore, just left and right and is not spawn above my player either, it's spawning at the bottom?