Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ce6f399

Browse files
Added character teleporting code
1 parent 2687ceb commit ce6f399

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

‎Assets/Scripts/CharacterMover.cs‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ public class CharacterMover : MonoBehaviour
4646
[Tooltip("The terminal velocity of the character.")]
4747
[SerializeField]
4848
private float terminalVelocity = -1;
49+
50+
/// <summary>
51+
/// The position to teleport the player to.
52+
/// </summary>
53+
[Tooltip("The position to teleport the player to.")]
54+
[SerializeField]
55+
private Vector3 teleportPosition = new(0, 0.5f, 0);
56+
57+
/// <summary>
58+
/// The rotation to teleport the player to.
59+
/// </summary>
60+
[Tooltip("The rotation to teleport the player to.")]
61+
[SerializeField]
62+
private Vector3 teleportRotation = Vector3.zero;
4963

5064
/// <summary>
5165
/// The character controller to move.
@@ -102,6 +116,22 @@ private void Update()
102116
// Cache the transform for performance since otherwise we would be accessing it multiple times.
103117
Transform t = transform;
104118

119+
// Teleport the player when R is pressed.
120+
if (Keyboard.current.rKey.wasPressedThisFrame)
121+
{
122+
// Disable to character controller so we can move the player via the transform.
123+
_controller.enabled = false;
124+
125+
// Set the position.
126+
t.position = teleportPosition;
127+
128+
// Set the rotation.
129+
t.eulerAngles = teleportRotation;
130+
131+
// Enable the character controller so it can move again.
132+
_controller.enabled = true;
133+
}
134+
105135
// Rotate on the y (green) axis for turning.
106136
t.Rotate(0, look * lookSpeed * Time.deltaTime, 0);
107137

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /