- Home /
Question by
Diamonddoggames · Sep 21, 2020 at 11:54 PM ·
teleportteleporting
Player Keeps on Resetting to original position
I have a raycast on another script that activates a function on a different script
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo, range))
{
if (hitInfo.transform.CompareTag("Interactive"))
{
IsHittingInteractive = true;
if (Input.GetKeyDown(KeyCode.E))
{
//aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa (don't mind this)
Ray rayE = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hitInfoE;
if (Physics.Raycast(ray, out hitInfoE, range))
{
#region TeleportE
TeleportE teleE = hitInfoE.transform.GetComponent<TeleportE>();
if (teleE != null)
{
teleE.teleport(); // this tells the script to activate the function
}
#endregion
#region PressEToActivate
#endregion
}
This script sees if the other script right above this one activates the function and teleports the player
public void teleport()
{
print("teleport : Player");
player.transform.position = teleportTransform.position;
}
When I press 'E' everything works as intended but the teleporting doesn't work. It teleports the player but then resets the player to its original position but it only teleports the player for a frame.
Comment
I don't see any issues apparent in the code you shared, so the player's position might be changed somewhere else. I recommend searching your project for every time the player's position is changed in any way. Add a debug log below or above each time it's changed. Then when you teleport, see what debugs are called after it.
Your answer