Skip to content

Commit 225ba7a

Browse files
Merge pull request #11391 from RespiteFromReality/3d_transform_page
Fixes to "Using 3D transforms" page
1 parent a502dee commit 225ba7a

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed
10.2 KB
Loading

tutorials/3d/using_transforms.rst

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -241,18 +241,24 @@ Obtaining information
241241

242242
You might be thinking at this point: **"Ok, but how do I get angles from a transform?"**. The answer again is: you don't. You must do your best to stop thinking in angles.
243243

244-
Imagine you need to shoot a bullet in the direction your player is facing. Just use the forward axis (commonly ``Z`` or ``-Z``).
244+
Imagine you need to shoot a bullet in the direction your player is facing. Just use the forward axis.
245245

246246
.. tabs::
247247
.. code-tab:: gdscript GDScript
248248

249+
# On RigidBody3D.
250+
251+
# Keep in mind that -Z is forward.
249252
bullet.transform = transform
250-
bullet.speed = transform.basis.z * BULLET_SPEED
253+
bullet.linear_velocity = -transform.basis.z * BULLET_SPEED
251254

252255
.. code-tab:: csharp
253256

254-
bullet.Transform = transform;
255-
bullet.LinearVelocity = transform.Basis.Z * BulletSpeed;
257+
// On RigidBody3D.
258+
259+
// Keep in mind that -Z is forward.
260+
bullet.Transform = Transform;
261+
bullet.LinearVelocity = -Transform.Basis.Z * BulletSpeed;
256262

257263
Is the enemy looking at the player? Use the dot product for this (see the :ref:`doc_vector_math` tutorial for an explanation of the dot product):
258264

@@ -278,35 +284,47 @@ Strafe left:
278284
.. tabs::
279285
.. code-tab:: gdscript GDScript
280286

281-
# Remember that +X is right
287+
# On CharacterBody3D.
288+
289+
# Keep in mind that -X is left.
282290
if Input.is_action_pressed("strafe_left"):
283-
translate_object_local(-transform.basis.x)
291+
velocity = -transform.basis.x * MOVE_SPEED
292+
293+
move_and_slide()
284294

285295
.. code-tab:: csharp
286296

287-
// Remember that +X is right
297+
// On CharacterBody3D.
298+
299+
// Keep in mind that -X is left.
288300
if (Input.IsActionPressed("strafe_left"))
289301
{
290-
TranslateObjectLocal(-Transform.Basis.X);
302+
Velocity = -Transform.Basis.X * MoveSpeed;
291303
}
292304

305+
MoveAndSlide();
306+
293307
Jump:
294308

295309
.. tabs::
296310
.. code-tab:: gdscript GDScript
297311

298-
# Keep in mind Y is up-axis
312+
# On CharacterBody3D.
313+
314+
# Keep in mind that +Y is up.
299315
if Input.is_action_just_pressed("jump"):
300316
velocity.y = JUMP_SPEED
301317

302318
move_and_slide()
303319

304320
.. code-tab:: csharp
305321

306-
// Keep in mind Y is up-axis
322+
// On CharacterBody3D.
323+
324+
// Keep in mind that +Y is up.
307325
if (Input.IsActionJustPressed("jump"))
308326
{
309-
velocity.Y = JumpSpeed;
327+
Velocity = Vector3.Up * JumpSpeed;
310328
}
311329

312330
MoveAndSlide();
@@ -332,8 +350,8 @@ Example of looking around, FPS style:
332350
func _input(event):
333351
if event is InputEventMouseMotion and event.button_mask & 1:
334352
# modify accumulated mouse rotation
335-
rot_x += event.relative.x * LOOKAROUND_SPEED
336-
rot_y += event.relative.y * LOOKAROUND_SPEED
353+
rot_x -= event.relative.x * LOOKAROUND_SPEED
354+
rot_y -= event.relative.y * LOOKAROUND_SPEED
337355
transform.basis = Basis() # reset rotation
338356
rotate_object_local(Vector3(0, 1, 0), rot_x) # first rotate in Y
339357
rotate_object_local(Vector3(1, 0, 0), rot_y) # then rotate in X
@@ -349,8 +367,8 @@ Example of looking around, FPS style:
349367
if (@event is InputEventMouseMotion mouseMotion)
350368
{
351369
// modify accumulated mouse rotation
352-
_rotationX += mouseMotion.Relative.X * LookAroundSpeed;
353-
_rotationY += mouseMotion.Relative.Y * LookAroundSpeed;
370+
_rotationX -= mouseMotion.Relative.X * LookAroundSpeed;
371+
_rotationY -= mouseMotion.Relative.Y * LookAroundSpeed;
354372

355373
// reset rotation
356374
Transform3D transform = Transform;

0 commit comments

Comments
 (0)