teleport in facing direction

Hello, I am making an action game and when I press space bar I want my character to teleport in the direction. I’ve tried vector3.forward but it just teleports the player in the directon the camera is facing. Can you please help?

Thanks in advance.

I’m a bit confused: when you say you’re using Vector3.forward, do you actually mean transform.forward? If you’re actually using Vector3.forward, you will always be teleported in the positive z direction, so you probably only think it’s the direction of the camera because that’s the direction your camera happens to be facing.

What you need to do is use the forward of the character, which is transform.forward (in a script within the character GameObject) or character.transform.forward (in a script in some other GameObject, where character is a reference to the character GameObject).

To go some set distance, use:

character.transform.position += character.transform.forward * desiredDistance;

Good luck.