(SOLVED) Need help with warping the player through rooms.

Doober

Member
So I know how to make the object that warps the player through the different rooms because I have a separate game that I was working on and it worked out fine (that game was transferred over from gm 1.4 to gm2), here's the code of that original object:

obj_player_1.x = target_x;
obj_player_1.y = target_y;
room_goto(target_r);

and then I add the variables in the objects creation code in the specific rooms they are tied with. I copied this code (which worked fine before) into the new object but for some reason the object warps the player to the right room but in the wrong spot. It spawns the player to the coords where the player was in the previous room when they warped, rather than to the coords that I had set. If anyone can tell me why this is happening now I would be very grateful, sorry if this was a bit long but I just want to be sure that I describe my problem in enough detail to help people understand it better. :3
 

Doober

Member
By



do you mean that target_x and target_y are defined in the room you're going to?
I declare the x, y, and room values in the objects creation code that tell it which room and where to spawn the character next, I learned it from shawn spalding.
 

Doober

Member
I don't think the problem is with these codes
Because these codes are the same in GameMaker 1.4 and 2.x.
That's what I was thinking, but I can't figure out what is causing this problem and its been making it a very frustrating process.
 

Doober

Member
1) Is obj_player_1 persistent?
2) Is there an instance of obj_player_1 already in target_r?
1) Yes, the player is persistent.
2) Only in the original room, he is supposed to warp to the other rooms, at least that how it worked in my last game.
 

woods

Member
if the obj_player is persistent, it will keep its variables when it goes into another room.. thats what persistent means right?
(this would include its x/y positions)


edit:
it would help if you showed some relevant code.. player, warp object, landing point, etc..
 

Gamebot

Member
Is said person always going to the same spot every time when they go to a new room? If so why not just place them where they need to go.


EDIT: I think that code works based on needing an x and y position when they hit another instance such as a door...ect

I would have two globals for x and y so when ever I hit a specific instance such, as a door, that instance sets my global x and y and goto for the next room. Then using the room_start event I would run instance_create...with my global x and y in each room.
 
Last edited:

TheouAegis

Member
If the player is persistent, then updating its coordinates before the room transition would give it the updated coordinates in the next room. As long as only 1 instance then exists in the next room, the original code should be fine.

If the player were not persistent, saving the target_x and target_y in global variables before transitioning, then moving the instance during the Create or Room Start event would also work.

--------

Comment out the room_goto(target_r) line. Does the player instance change position then?

Also, make sure neither the player nor the object with this code is flagged as solid. (shouldn't cause this issue, but you never know sometimes)
 
Last edited:

Doober

Member
If the player is persistent, then updating its coordinates before the room transition would give it the updated coordinates in the next room. As long as only 1 instance then exists in the next room, the original code should be fine.

If the player were not persistent, saving the target_x and target_y in global variables before transitioning, then moving the instance during the Create or Room Start event would also work.

--------

Comment out the room_goto(target_r) line. Does the player instance change position then?

Also, make sure neither the player nor the object with this code is flagged as solid. (shouldn't cause this issue, but you never know sometimes)
Oh my god, it's working now. All I did was uncheck the solid option on the player and everything just fixed itself, which is strange because that was never an issue before. Thank you so much for helping me to solve this problem, as well to everyone else who gave their time to help me too. You guys rock!
 

TheouAegis

Member
Oh my god, it's working now. All I did was uncheck the solid option on the player and everything just fixed itself, which is strange because that was never an issue before. Thank you so much for helping me to solve this problem, as well to everyone else who gave their time to help me too. You guys rock!
I am actually shocked that worked. I was pretty sure the 'solid snap' occurs before the collision event. If you want to actually use solid for whatever reason, then in addition to setting x and y, also set xprevious and yprevious.
 

Doober

Member
I am actually shocked that worked. I was pretty sure the 'solid snap' occurs before the collision event. If you want to actually use solid for whatever reason, then in addition to setting x and y, also set xprevious and yprevious.
Thanks, ya I think that I might try that out. Thanks again! :3
 
Top