playMaker

Author Topic: Set player position [SOLVED]  (Read 9964 times)

Timo

  • Playmaker Newbie
  • *
  • Posts: 11
Set player position [SOLVED]
« on: October 18, 2013, 12:35:23 PM »
Hi!

I'm new to playmaker, but I've been getting the foundations rather quickly, and this issue is just stumping me. I have an FSM that gets the player position and loads it into a global variable before loading a new scene. When a player exits that scene another FSM sets the player position based off that same global variable.

The first time you go into a new scene, then come back to the main one it sets your position correctly. The problem is if you go into another scene and come back, it loads your position from the original place you left from the first time.

I'm not sure if it's because the objects with the FSM's for the player to go into a new scene are duplicates of each other. But I would think that since they get the position and rotation and set them in a global variable it wouldn't matter.

Here's the FSM for getting position and rotation before loading a level:


and here's the FSM for the main scene to load your position and rotation from the global variable:


Thank you for your help!
« Last Edit: November 04, 2013, 10:07:53 AM by Timo »

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Set player position
« Reply #1 on: October 19, 2013, 01:43:10 PM »
My first guess here from the info you provided, and someone please correct me if I am wrong, but it looks like your loading a prefab each scene. Which probably means that the first time you save the global for that pre fab your actually saving it for that current gameobject of that scene. When your new scene comes along its loading a pre fab but that pre fab is not the same Game object so the the global is getting regurgitated with no new info to write. Maybe you need to set a tag for your prefab and make the call to write your global when you have a game object with the same tag.

Timo

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Set player position
« Reply #2 on: October 21, 2013, 09:54:23 AM »
ahhh great suggestion, I'll check it out this morning and let you know how it goes!

Thanks!

Timo

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Set player position
« Reply #3 on: October 21, 2013, 01:42:16 PM »
Looks like I'm still running into issues with this one. I've set the trigger to only trigger when the Player tag is on the prefab colliding with it, which then gets position from the game object which the player controller is a child of. When I go back to that scene, it still doesn't load the correct position and rotation. This is the new setup:



Then loading back into the scene:

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Set player position
« Reply #4 on: October 21, 2013, 04:16:27 PM »
Can you attach your scene file?

Timo

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Set player position
« Reply #5 on: October 21, 2013, 04:28:34 PM »
Here it is, thanks!

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Set player position
« Reply #6 on: October 21, 2013, 05:32:29 PM »
I couldn't really play with the scene because it was missing your pre fabs, but you might want to look into your load level action. There are 2 options that might help you do this better. Additive loading and "Don't destroy on level load".

Timo

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Set player position
« Reply #7 on: October 21, 2013, 06:22:15 PM »
I tried both those options, but loading it additive causes overlay issues, and for some reason my only options to not destroy on load are bools. I sent you an email with the project, maybe you can see something I don't.

Thanks again for the help!

Timo

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Set player position
« Reply #8 on: October 23, 2013, 10:05:47 AM »
Any other thoughts?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Set player position
« Reply #9 on: October 24, 2013, 01:36:28 AM »
Hi,

I would not use global variables for this, I would use PlayerPrefs, this way even if the player quits the game and restart you know he's last position or that position he's supposed to start.

bye,

 Jean

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Set player position
« Reply #10 on: October 29, 2013, 12:56:21 AM »
Something Ive started doing and it's worked pretty well is to search for Game objects in my scene by a tag. Ive created a template in Playmaker that uses 'Find Game Object'(just by the tag) and 'Game Object is Null' and I save the Game object to a Game Object var (_objectGO). Now if it's null then I will send an event to a state that will wait 1 frame and then go back and look again. If it is not null then I can branch out to my logic.
I do this with pre fabs because at the start state your pre fab(clone) might not be found and if you try to drag and drop your prefab into a Gameobject slot on an Action, it will look for the Prefab and not the prefab(clone) which is actually in the scene.
Now you can use a reference to you prefab clone in any GameObject field by choosing to use the property.

In your specific case where you are loading new scenes you are also using a prefab clone which you are trying to save a position you can load on scene changes. I believe you can use this method to find your clone and always be able to update your position by only performing the logic after you have found your pre fab.

The only thing to keep in mind is this tag has to be unique for this object and not something generic you might have multi objects sharing.
« Last Edit: October 29, 2013, 01:08:22 AM by redikann »

Timo

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Set player position
« Reply #11 on: October 29, 2013, 05:29:20 PM »
Hi,

I would not use global variables for this, I would use PlayerPrefs, this way even if the player quits the game and restart you know he's last position or that position he's supposed to start.

bye,

 Jean

I'm unable to get it working by tag, so I'm looking into play prefs, but I don't see anything about grabbing Vecter3. how would I get position and set position with the player prefs?

thanks!

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Set player position
« Reply #12 on: October 29, 2013, 06:07:00 PM »
Well you could use playerpref floats for x, y and z . You can breakdown a vector 3 with the "get vector3 xyz" action. The opposite would be "Set vector3 xyz".

Timo

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Set player position
« Reply #13 on: October 30, 2013, 01:36:31 PM »
Thanks for helping still. So I've setup the trigger to get vector XYZ, then store them in floats, then I have PlayerPrefs Get Float getting the XYZ from those variables. I typed in a different keyname for each variable.

When the scene loads I have it set the PlayerPrefs floats into variables, then set vector 3 xyz and finally set player position. The problem is, still doesn't work. it still spawns me at the initial spawn location. Maybe I'm not setting the correctly? I haven't found a place to create a key that you can select fomr the dropdown list anywhere.

thanks again for your help.

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Set player position
« Reply #14 on: October 30, 2013, 09:38:42 PM »
I never saw your email with the project. Can you trying ending it to me again?