- Home /
FPS teleport flicker one frame- but works fine with main camera.
I have a simple teleport script that works with my main camera. however when I switch to the prefab of the FPS. disable my main camera. change my game object in script from main camera to FPS controller. my player does not teleport. However I do see a flicker of the landing point each time I hit the trigger area.
It wants to teleport but something seems to be holding it back.
player.transform.position = landing1.transform.position;
humm, you dont have on the landing1 another collider who teleport it again to the first? maybe this just are doing a poing-pong between landing areas,
sorry, is very difficult get a clue with so lack of info...
Answer by bridget_cloud · Sep 10, 2019 at 06:25 PM
I had the same issue and disabled the FirstPersonController script before teleporting the FPS controller. I enabled it immediately after teleporting into the area and it seems to work fine (for now).
Answer by unity_MUIlMppJ96RwuQ · Dec 05, 2019 at 09:58 AM
Hi, @bridget_cloud I have the same issue but I'm really new to unity and coding. Wouls you explain to me how you can disable FPS Controller script before teleporting? Like If you were talking to a 5 year old child... thanks a lot,Hi I'm new to unity and coding. I have the same issue, would you explain to me how I can disable the FPS script as you said? Thanks a lot
@unity_$$anonymous$$UIl$$anonymous$$ppJ96RwuQ Sure, but before I do I just wanted to mention that this doesn't seem to be an issue in version 2019.2.1. I'm able to transport the player by setting it's position to the spawn point position.
But here is what I did for version 2018:
**Note that I created a GameObject reference variable for the "player" and a Transform reference variable for the spawn point ("spawnPt") and then initialized them accordingly.
First I created a reference variable for the First Person Controller script:
FirstPersonController fp;
Next, I initialized it in the Start method (of course I'm using a game object reference variable "player":
fp = player.GetComponent<FirstPersonController>();
Then, in the Update method, I do my check to see if the user is trying to initiate the transport by pressing the E key (and also being near the door):
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.E) && nearDoor){
//code to transport player here
}
$$anonymous$$y code to transport the player first disables the FPC script, moves the player, and then starts a coroutine to turn the script back on. (It also sets my bool variable that checks to see if they are able to move to false):
nearDoor = false; //So the player won't keep moving back to the spawnPt with accidental key hits
fp.enabled = false; //Disables FPC script
player.transform.position = spawnPt.position; //Sets the players position to the same as the spawn point
StartCoroutine(TurnOnScript(.25f));
Here is the code for TurnOnScript:
private IEnumerator TurnOnScript(float time){
yield return new WaitForSeconds(time);
fp.enabled = true;
}
Hope that helps. If you need any further clarification, let me know.
Your answer
Follow this Question
Related Questions
First Person Player Teleportation 10 Answers
moving is all messed up 1 Answer
Creating a character from a capsule 0 Answers
Insert First Person Controller, but can not move in Game view 3 Answers