Skip to main content
added 306 characters in body
Source Link
Zibelas
  • 5k
  • 2
  • 15
  • 26
  1. First you need to save the position ONLY when you request it. Currently your code is spam saving the location (twice per FixedUpdate). This needs to be changed. Make a new Method for it, check if a certain key is pressed and only than save the location.
  2. Do not save those locations to playerpref. PlayerPrefs are for storing and accessing player preferences between game sessions. All you need to have is a local Vector2 in your controller that saves the position.
  3. Since you just want a teleport and not the block option as in the video, you can just display an image at the position from 2). No rigidbody/ boxcollider needed on it.
  4. https://docs.unity3d.com/ScriptReference/MonoBehaviour.Invoke.html You call in the same condition as under 2) a teleport back method. The example code even shows how to add the 2sec delay. Your teleport code just assigns the saved vector2 as the new position of your player, removes the image from 3) and should as well set the vector2 to null.
  5. As a tip, do not capture user input in Fixedupdate. Input.GetKeyDown is only true in the frame it gets captured and not afterwards. That means you might miss the keypress and your code is not working as you would expect it.

If you have are stuck on one of the points, please update your code and I will further explain the step.

A simple save can be as easy as

private Vector2 saveThisPosition;
private void PlayerPosSave() {
    saveThisPosition = transform.position;
}

Within your playerController, you can access always saveThisPosition and you have the location of the place where you pressed your key. The switch between the object that you spawned and the current Player is just switching their positions.

private void SwitchWithSavedPosition() {
    Vector2 temp = transform.position;
    transform.position = saveThisPosition;
    spawnedGameObject.transform.position = temp;
}

spawnedGameObject is the reference to the old player that you have to create when you press your saveLocation key.

  1. First you need to save the position ONLY when you request it. Currently your code is spam saving the location (twice per FixedUpdate). This needs to be changed. Make a new Method for it, check if a certain key is pressed and only than save the location.
  2. Do not save those locations to playerpref. PlayerPrefs are for storing and accessing player preferences between game sessions. All you need to have is a local Vector2 in your controller that saves the position.
  3. Since you just want a teleport and not the block option as in the video, you can just display an image at the position from 2). No rigidbody/ boxcollider needed on it.
  4. https://docs.unity3d.com/ScriptReference/MonoBehaviour.Invoke.html You call in the same condition as under 2) a teleport back method. The example code even shows how to add the 2sec delay. Your teleport code just assigns the saved vector2 as the new position of your player, removes the image from 3) and should as well set the vector2 to null.
  5. As a tip, do not capture user input in Fixedupdate. Input.GetKeyDown is only true in the frame it gets captured and not afterwards. That means you might miss the keypress and your code is not working as you would expect it.

If you have are stuck on one of the points, please update your code and I will further explain the step.

A simple save can be as easy as

private Vector2 saveThisPosition;
private void PlayerPosSave() {
    saveThisPosition = transform.position;
}

Within your playerController, you can access always saveThisPosition and you have the location of the place where you pressed your key.

  1. First you need to save the position ONLY when you request it. Currently your code is spam saving the location (twice per FixedUpdate). This needs to be changed. Make a new Method for it, check if a certain key is pressed and only than save the location.
  2. Do not save those locations to playerpref. PlayerPrefs are for storing and accessing player preferences between game sessions. All you need to have is a local Vector2 in your controller that saves the position.
  3. Since you just want a teleport and not the block option as in the video, you can just display an image at the position from 2). No rigidbody/ boxcollider needed on it.
  4. https://docs.unity3d.com/ScriptReference/MonoBehaviour.Invoke.html You call in the same condition as under 2) a teleport back method. The example code even shows how to add the 2sec delay. Your teleport code just assigns the saved vector2 as the new position of your player, removes the image from 3) and should as well set the vector2 to null.
  5. As a tip, do not capture user input in Fixedupdate. Input.GetKeyDown is only true in the frame it gets captured and not afterwards. That means you might miss the keypress and your code is not working as you would expect it.

If you have are stuck on one of the points, please update your code and I will further explain the step.

A simple save can be as easy as

private Vector2 saveThisPosition;
private void PlayerPosSave() {
    saveThisPosition = transform.position;
}

Within your playerController, you can access always saveThisPosition and you have the location of the place where you pressed your key. The switch between the object that you spawned and the current Player is just switching their positions.

private void SwitchWithSavedPosition() {
    Vector2 temp = transform.position;
    transform.position = saveThisPosition;
    spawnedGameObject.transform.position = temp;
}

spawnedGameObject is the reference to the old player that you have to create when you press your saveLocation key.

added 307 characters in body
Source Link
Zibelas
  • 5k
  • 2
  • 15
  • 26
  1. First you need to save the position ONLY when you request it. Currently your code is spam saving the location (twice per FixedUpdate). This needs to be changed. Make a new Method for it, check if a certain key is pressed and only than save the location.
  2. Do not save those locations to playerpref. PlayerPrefs are for storing and accessing player preferences between game sessions. All you need to have is a local Vector2 in your controller that saves the position.
  3. Since you just want a teleport and not the block option as in the video, you can just display an image at the position from 2). No rigidbody/ boxcollider needed on it.
  4. https://docs.unity3d.com/ScriptReference/MonoBehaviour.Invoke.html You call in the same condition as under 2) a teleport back method. The example code even shows how to add the 2sec delay. Your teleport code just assigns the saved vector2 as the new position of your player, removes the image from 3) and should as well set the vector2 to null.
  5. As a tip, do not capture user input in Fixedupdate. Input.GetKeyDown is only true in the frame it gets captured and not afterwards. That means you might miss the keypress and your code is not working as you would expect it.

If you have are stuck on one of the points, please update your code and I will further explain the step.

A simple save can be as easy as

private Vector2 saveThisPosition;
private void PlayerPosSave() {
    saveThisPosition = transform.position;
}

Within your playerController, you can access always saveThisPosition and you have the location of the place where you pressed your key.

  1. First you need to save the position ONLY when you request it. Currently your code is spam saving the location (twice per FixedUpdate). This needs to be changed. Make a new Method for it, check if a certain key is pressed and only than save the location.
  2. Do not save those locations to playerpref. PlayerPrefs are for storing and accessing player preferences between game sessions. All you need to have is a local Vector2 in your controller that saves the position.
  3. Since you just want a teleport and not the block option as in the video, you can just display an image at the position from 2). No rigidbody/ boxcollider needed on it.
  4. https://docs.unity3d.com/ScriptReference/MonoBehaviour.Invoke.html You call in the same condition as under 2) a teleport back method. The example code even shows how to add the 2sec delay. Your teleport code just assigns the saved vector2 as the new position of your player, removes the image from 3) and should as well set the vector2 to null.
  5. As a tip, do not capture user input in Fixedupdate. Input.GetKeyDown is only true in the frame it gets captured and not afterwards. That means you might miss the keypress and your code is not working as you would expect it.

If you have are stuck on one of the points, please update your code and I will further explain the step.

  1. First you need to save the position ONLY when you request it. Currently your code is spam saving the location (twice per FixedUpdate). This needs to be changed. Make a new Method for it, check if a certain key is pressed and only than save the location.
  2. Do not save those locations to playerpref. PlayerPrefs are for storing and accessing player preferences between game sessions. All you need to have is a local Vector2 in your controller that saves the position.
  3. Since you just want a teleport and not the block option as in the video, you can just display an image at the position from 2). No rigidbody/ boxcollider needed on it.
  4. https://docs.unity3d.com/ScriptReference/MonoBehaviour.Invoke.html You call in the same condition as under 2) a teleport back method. The example code even shows how to add the 2sec delay. Your teleport code just assigns the saved vector2 as the new position of your player, removes the image from 3) and should as well set the vector2 to null.
  5. As a tip, do not capture user input in Fixedupdate. Input.GetKeyDown is only true in the frame it gets captured and not afterwards. That means you might miss the keypress and your code is not working as you would expect it.

If you have are stuck on one of the points, please update your code and I will further explain the step.

A simple save can be as easy as

private Vector2 saveThisPosition;
private void PlayerPosSave() {
    saveThisPosition = transform.position;
}

Within your playerController, you can access always saveThisPosition and you have the location of the place where you pressed your key.

added 7 characters in body
Source Link
Zibelas
  • 5k
  • 2
  • 15
  • 26
  1. First you need to save the position ONLY when you request it. Currently your code is spam saving the location (twice per FixedUpdate). This needs to be changed. Make a new Method for it, check if a certain key is pressed and only than save the location.
  2. Do not save those locations to playerpref. PlayePrefsPlayerPrefs are for storing and accessing player preferences between game sessions. All you need to have is a local Vector2 in your controller that saves the position.
  3. Since you just want a teleport and not the block option as in the video, you can just display an image at the position from 2). No rigidbody/ boxcollider needed on it.
  4. https://docs.unity3d.com/ScriptReference/MonoBehaviour.Invoke.html You call in the same condition inas under 2) a teleport back method. The example code even shows how to add the 2sec delay. Your teleport code just assigns the saved vector2 as the new position of your player, removes the image from 3) and should as well set the vector2 to null.
  5. As a tip, do not capture user input in Fixedupdate. Input.GetKeyDown is only true in the frame it gets captured and not afterwards. That means you might miss the keypress and your code is not working as you would expect it.

If you have are stuck on one of the points, please update your code and I will further explain the step.

  1. First you need to save the position ONLY when you request it. Currently your code is spam saving the location (twice per FixedUpdate). This needs to be changed. Make a new Method for it, check if a certain key is pressed and only than save the location.
  2. Do not save those locations to playerpref. PlayePrefs are for storing and accessing player preferences between game sessions. All you need to have is a local Vector2 in your controller that saves the position.
  3. Since you just want a teleport and not the block option as in the video, you can just display an image at the position from 2). No rigidbody/ boxcollider needed on it.
  4. https://docs.unity3d.com/ScriptReference/MonoBehaviour.Invoke.html You call in the same condition in 2) a teleport back method. The example code even shows how to add the 2sec delay. Your teleport code just assigns the saved vector2 as the new position of your player, removes the image from 3) and should as well set the vector2 to null.
  5. As a tip, do not capture user input in Fixedupdate. Input.GetKeyDown is only true in the frame it gets captured and not afterwards. That means you might miss the keypress and your code is not working as you would expect it.

If you have are stuck on one of the points, please update your code and I will further explain the step.

  1. First you need to save the position ONLY when you request it. Currently your code is spam saving the location (twice per FixedUpdate). This needs to be changed. Make a new Method for it, check if a certain key is pressed and only than save the location.
  2. Do not save those locations to playerpref. PlayerPrefs are for storing and accessing player preferences between game sessions. All you need to have is a local Vector2 in your controller that saves the position.
  3. Since you just want a teleport and not the block option as in the video, you can just display an image at the position from 2). No rigidbody/ boxcollider needed on it.
  4. https://docs.unity3d.com/ScriptReference/MonoBehaviour.Invoke.html You call in the same condition as under 2) a teleport back method. The example code even shows how to add the 2sec delay. Your teleport code just assigns the saved vector2 as the new position of your player, removes the image from 3) and should as well set the vector2 to null.
  5. As a tip, do not capture user input in Fixedupdate. Input.GetKeyDown is only true in the frame it gets captured and not afterwards. That means you might miss the keypress and your code is not working as you would expect it.

If you have are stuck on one of the points, please update your code and I will further explain the step.

Source Link
Zibelas
  • 5k
  • 2
  • 15
  • 26
Loading