Changing player y position without being affected by gravity

I’m using the following code to create a teleporting effect. When the user presses a directional arrow and presses shift it triggers the teleport. The problem I’m having is when the player wants to teleport up and down. Since there is gravity in the scene it appears to shorten the distance of the teleport. Any ideas on how I could fix this?

using UnityEngine;
using System.Collections;

public class PlayerMovement : MonoBehaviour {

	//A reference to the players 2D Rigidbody
	public Rigidbody2D playerRidgidbody;

	//Needs to be messed with so it is appropriate 
	//How fast the player moves
	private float moveSpeed = 5;
	private float jumpForce = 7;
	private float dashDistance = 3;

	private int dashCharges = 2;

	private bool grounded;

	private Vector2 playerVelocity;
	
	// Update is called once per frame
	void FixedUpdate () {

		//Need to change KeyCode to Custom input.
		//Moves player to the right
		if (Input.GetKey (KeyCode.RightArrow)) {
			if(Input.GetKeyDown(KeyCode.LeftShift) && dashCharges > 0){
				Vector2 temp = transform.position;
				temp.x += dashDistance;
				transform.position = temp;
			} else {
				playerRidgidbody.velocity = new Vector2 (moveSpeed, playerRidgidbody.velocity.y);
			}
		}
		//Moves player to the left
		else if (Input.GetKey (KeyCode.LeftArrow)) {
			if(Input.GetKeyDown(KeyCode.LeftShift) && dashCharges > 0){
				Vector2 temp = transform.position;
				temp.x -= dashDistance;
				transform.position = temp;
			} else {
				playerRidgidbody.velocity = new Vector2 (-moveSpeed, playerRidgidbody.velocity.y);
			}
		} else {
			playerRidgidbody.velocity = new Vector2(0, playerRidgidbody.velocity.y);
		}
             
		if (Input.GetKey (KeyCode.UpArrow) && Input.GetKeyDown (KeyCode.LeftShift) && dashCharges > 0) {
			Debug.Log("up dash");
			Vector2 temp = transform.position;
			temp.y += dashDistance;
			transform.position = temp;
		} else if(Input.GetKey (KeyCode.DownArrow) && Input.GetKeyDown(KeyCode.LeftShift) && dashCharges > 0) {
			Debug.Log("down dash");
			Vector2 temp = transform.position;
			temp.y -= dashDistance;
			transform.position = temp;
		}

		//Used to detect if the player is grounded 
		RaycastHit2D hit = Physics2D.Raycast (transform.position, -Vector2.up, .5f);

		//Debug.DrawRay (transform.position, -Vector2.up, Color.red, .5f);

		if (hit.collider.tag == "Ground") {
			//Debug.Log ("Grounded");
			grounded = true;
		} else {
			grounded = false;
		}

		if (Input.GetKey (KeyCode.Space) && grounded == true) {
			//Debug.Log ("Pressing space");
			playerRidgidbody.velocity = new Vector2(playerRidgidbody.velocity.x, jumpForce);
		}
	}
}

Have you tried to use;

Rigidbody.useGravity = false;

This is what it appears to be, a bool to disable gravity.
You could probably use this during the teleport.

I haven’t used this my self, so the implementation would be up to you. But I feel like it’s exactly what you’re looking for.

EDIT/ Oh I see you’re making a 2D game, not sure if this still counts but I figure it deserves a look.

Note: I am new to Unity so my answer might be completely off.

You are handling inputs in the FixedUpdate, which is generally used for Rigidbody manipulation. As far as I understand FixedUpdate get called after Update and before LateUpdate(where you probably handle gravity). So what is possibly going on is that line temp.y -= dashDistance; get executed before gravity is applied. So you dashing position suppose to be change, let say, from y = 0f to y = 5f, but then gravitation in LateUpdate get applied, so y = 5f becomes y = 4f.

Thus, try to move your dashing logic in either Update or Late update functions.

Reference:
Update: Unity - Scripting API: MonoBehaviour.Update()

FixedUpdate:

LateUpdate: Unity - Scripting API: MonoBehaviour.LateUpdate()