Skip to content

Commit 19546c8

Browse files
authored
Merge pull request godotengine#7997 from toafloast/tryingtofixthis
Update ray casting tutorial.
2 parents 502ec0f + 7183ef3 commit 19546c8

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed
-4.32 KB
Binary file not shown.
10.9 KB
Loading

tutorials/physics/ray-casting.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ with Area3D, the boolean parameter ``collide_with_areas`` must be set to ``true`
156156

157157
.. tabs::
158158
.. code-tab:: gdscript GDScript
159+
159160
const RAY_LENGTH = 1000
160161

161162
func _physics_process(delta):
@@ -178,7 +179,7 @@ about the world around it. One problem with this is that the same character
178179
has a collider, so the ray will only detect its parent's collider,
179180
as shown in the following image:
180181

181-
.. image:: img/raycast_falsepositive.png
182+
.. image:: img/raycast_falsepositive.webp
182183

183184
To avoid self-intersection, the ``intersect_ray()`` parameters object can take an
184185
array of exceptions via its ``exclude`` property. This is an example of how to use it
@@ -191,7 +192,7 @@ from a CharacterBody2D or any other collision object node:
191192

192193
func _physics_process(delta):
193194
var space_state = get_world_2d().direct_space_state
194-
var query = PhysicsRayQueryParameters2D.create(global_position, enemy_position)
195+
var query = PhysicsRayQueryParameters2D.create(global_position, player_position)
195196
query.exclude = [self]
196197
var result = space_state.intersect_ray(query)
197198

@@ -204,7 +205,7 @@ from a CharacterBody2D or any other collision object node:
204205
public override void _PhysicsProcess(double delta)
205206
{
206207
var spaceState = GetWorld2D().DirectSpaceState;
207-
var query = PhysicsRayQueryParameters2D.Create(globalPosition, enemyPosition);
208+
var query = PhysicsRayQueryParameters2D.Create(globalPosition, playerPosition);
208209
query.Exclude = new Godot.Collections.Array<Rid> { GetRid() };
209210
var result = spaceState.IntersectRay(query);
210211
}
@@ -230,7 +231,7 @@ member variable. The array of exceptions can be supplied as the last argument as
230231

231232
func _physics_process(delta):
232233
var space_state = get_world_2d().direct_space_state
233-
var query = PhysicsRayQueryParameters2D.create(global_position, enemy_position,
234+
var query = PhysicsRayQueryParameters2D.create(global_position, target_position,
234235
collision_mask, [self])
235236
var result = space_state.intersect_ray(query)
236237

@@ -243,7 +244,7 @@ member variable. The array of exceptions can be supplied as the last argument as
243244
public override void _PhysicsProcess(double delta)
244245
{
245246
var spaceState = GetWorld2D().DirectSpaceState;
246-
var query = PhysicsRayQueryParameters2D.Create(globalPosition, enemyPosition,
247+
var query = PhysicsRayQueryParameters2D.Create(globalPosition, targetPosition,
247248
CollisionMask, new Godot.Collections.Array<Rid> { GetRid() });
248249
var result = spaceState.IntersectRay(query);
249250
}

0 commit comments

Comments
 (0)