playMaker

Author Topic: Set Position Immediately Resets itself [SOLVED]  (Read 771 times)

EnkiDorado

  • Playmaker Newbie
  • *
  • Posts: 3
Set Position Immediately Resets itself [SOLVED]
« on: July 27, 2020, 02:00:50 AM »
I'm trying to make a simple door that teleports the player to an empty on the other side of itself.

Currently the player can walk up to the door and press 'e' to get teleported to the empty, but as soon as Set Position isn't running the player gets teleported back to their original position. I've disabled the player's movement FSM and the issue persists.

As of right now I have Set Position running every frame for a second simply for debug purposes, but that's it.

I'm assuming that somehow the player's position is being stored separately from the player's Game Object, but beyond that I'm not sure what needs to be done to fix this.
« Last Edit: July 27, 2020, 04:35:19 AM by EnkiDorado »

EnkiDorado

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Set Position Immediately Resets itself
« Reply #1 on: July 27, 2020, 03:01:31 AM »
After some debugging I've determined that the Character Controller isn't being moved with the player, so once Set Position is done with what it's doing the Controller is moving the Player back to it's original position. I guess from here I need to find a way to change the Controller's position.

EnkiDorado

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Set Position Immediately Resets itself
« Reply #2 on: July 27, 2020, 04:34:18 AM »
I've managed to solve it by disabling the controller during the teleport, then reenabling it in an additional state that also plays a sound effect. I'll include the entirety of the script below in case anyone runs into a similar issue to mine. I think I can set this thread to [SOLVED] from here.

Quote
public class playerCollisionToggle : MonoBehaviour
{
    //Calling variables.
    CharacterController controller;
    public bool playerCollisionToggleBool = true;

    void Start()
    {
        controller = GetComponent<CharacterController>();
    }

    // Within the state have a "Send Message" action that call's this method in the player's GameObject.
    // All the method is doing is running a switch statement that checks if the bool set at the start is true or false.
    // If true, it changes the bool to false and disables collision. If false, vice versa.
    void ToggleCollision()
    {
        switch (playerCollisionToggleBool)
        {
            case true:
                playerCollisionToggleBool = false;
                controller.enabled = false;
                break;
            case false:
                playerCollisionToggleBool = true;
                controller.enabled = true;
                break;
        }
    }
}

and the structure of the FSM should be below as well:

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Set Position Immediately Resets itself [SOLVED]
« Reply #3 on: July 28, 2020, 01:41:34 AM »
Hi,

 cool. I think you can achieve that with just actions as well right?

Bye,

 Jean