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

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

@ChocolatePinecone

Description

@ChocolatePinecone

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions