Forum rules - please read before posting.

Remembering player position after scene-surviving action list

Hi there!

Ok, so I have a scene surviving action list that does the following:

  1. The player looks at an inventory item and says something
  2. "Scene: Switch" to Scene B where an NPC says something (the player is not visible in this scene due to the PlayerStart being placed offscreen)
  3. "Scene: Switch" back to Scene A where the player says something

This works perfectly except for Step 3 where the player's position isn't maintained but he is instead teleported to the PlayerStart of Scene A.

I don't know where the player will be standing when the Action List is executed so I can't use a PlayerStart. If I were to switch players the position would be maintained, but since I'm using a "Scene: Switch" action I'm not sure how to get the same effect.

Thanks!

Comments

  • edited July 2019

    Try the "teleporting PlayerStart" trick I describe at the bottom of this post.

  • edited July 2019
    Thanks but the player might be doing this from any scene in the game. It doesn't seem feasible to have one PlaterStart for each scene, placed in every scene throughout the game.

    Besides it would cause confusion if the player was to enter the scene by walking from scene B to scene A as opposed to entering the scene by this cutscene.

    It would be awesome if the Scene:Switch action had a checkboxe like "Restore player position". If checked, this particular player would enter on the position he last left the scene.
  • I don't believe that would be widely-useful enough to warrant inclusion.

    Another method would be to create a new Vector3 global variable, and use that to temporarily record the player's position using the Object: Record transform Action in between steps 1. and 2.

    An Object: Transform Action could then be used following step 3. to reposition the Player to this variable's value (provided you also attach a Moveable component to their root).

  • Not sure how to record the player's position as he is not in the scene (player switching is allowed) and there is no "Is player" option on Object: Record Transform.

  • I ended up using what Alverik suggested here:
    https://adventurecreator.org/forum/discussion/6153/return-to-previous-scene-at-specific-position

    The only little problem now it that when Scene B shows, you can see the camera (which follows the player) travel from the position of the PlayerStart to the players new position. Any ideas how to tackle this?

    Thanks

  • Call the following to snap the active camera to it's target position:

    AC.KickStarter.mainCamera.attachedCamera.MoveCameraInstant ();
    

    I shall add an Is Player? checkbox to the Object: Record Transform Action.

  • edited July 2019

    thanks, but running that code in a custom action that is executed directly after the "Scene: Switch" action (in a scene surviving cutscene) had no effect.

    I also tried this:

    var camera = ((GameCamera2D)KickStarter.mainCamera.attachedCamera);
    var previousSpeed = camera.dampSpeed;
    camera.dampSpeed = float.MaxValue;
    KickStarter.mainCamera.attachedCamera.MoveCameraInstant();
    camera.dampSpeed = previousSpeed;

    But it also had no effect. However, if you remove the last line everything works, but then we're stuck with the wrong dampSpeed. I'm guessing it has to do with the camera not actually moving since after this action is executed, at which time it uses the current dampSpeed.

    Any ideas? Or maybe a new action is called for, that would record the player's position in a way that would be taken into account before locating the PlayerStart?

  • The Player's position before snapping to the PlayerStart would just be their position from the previous scene.

    It's not clear what's actually going on here. Try inserting a brief wait in between the Scene: Switch and the custom Action.

  • Inserting a brief wait didn't change anything, and if I waited long enough it was clear that when it does kick in, the damp speed is still used (so the camera isn't moved instantly).

    BTW: The same thing is true player switching between players in different scenes, the camera is moved from the PlayerStart to the player position and if the damp speed is low enough its definitely noticable.

  • The same thing is true player switching between players in different scenes, the camera is moved from the PlayerStart to the player position and if the damp speed is low enough its definitely noticable.

    This, at least, I can recreate - will investigate.

  • In SceneChanger.cs, find line 457:

    KickStarter.player.RepositionToTransform (npc.transform);
    

    Insert the following underneath:

    if (KickStarter.mainCamera != null && KickStarter.mainCamera.attachedCamera != null) KickStarter.mainCamera.attachedCamera.MoveCameraInstant ();
    

    Does that solve the issue in either or both scenarios?

  • No change in either scenario.

  • edited July 2019

    Move it instead to SaveSystem.cs' line 1661 - what then?

    If no change, PM me a repro package so that I can recreate both issues exactly.

  • Sweet, that fixed both scenarios!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.