Skip to content
This repository has been archived by the owner on Jun 29, 2024. It is now read-only.

Raycast2D does not work when Area2D scale x is -1 #113

Open
ChocolatePinecone opened this issue Apr 23, 2024 · 0 comments
Open

Raycast2D does not work when Area2D scale x is -1 #113

ChocolatePinecone opened this issue Apr 23, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@ChocolatePinecone
Copy link

Describe the bug
A simple raycast does not wield a result when the Area2D is mirrored (meaning scale.x = -1)

To Reproduce
Steps to reproduce the behavior:

  1. Create an empty Node2D scene and add a Area2D with a Rectangle shaped Collider
  2. Add an Area2D, position x: 500 y: 100
  3. Add a CollisionShape2D, size x: 200 y: 100
  4. Add the following script to the Area2D for drawing debug data:
extends Area2D


var intersection_detected := false


func _process(delta):
	var mousepos := get_global_mouse_position()
	
	var space := get_world_2d().space
	var space_state = PhysicsServer2D.space_get_direct_state(space)
	var query := PhysicsRayQueryParameters2D.create(mousepos, global_position)
	query.collide_with_areas = true
	query.collide_with_bodies = false
	var result := space_state.intersect_ray(query)
	
	intersection_detected = not result.is_empty()
	queue_redraw()
	

func _draw():
	if intersection_detected:
		$CollisionShape2D.shape.draw(get_canvas_item(), Color.YELLOW)
	else:
		$CollisionShape2D.shape.draw(get_canvas_item(), Color.WHITE)
	
	var mousepos := to_local(get_global_mouse_position())
	draw_line(mousepos, Vector2.ZERO, Color.BLUE)
  1. Now run the scene. You should see the collider in yellow, indicating a succesful raycast intersection with it.
  2. Stop running the scene and change the Area2D scale x to -1
  3. Run the scene again. You should now see the collider in white, indicating a raycast intersection could not be found, even though the drawn raycast line is clearly intersecting the collider.

Expected behavior
The raycast to return a correctly detected intersection

Versions:

  • OS: Windows 11 Business
  • Godot 4.2.1
  • Box2d 0.9.9
@ChocolatePinecone ChocolatePinecone added the bug Something isn't working label Apr 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant