Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Area2D does not scale with parent #93

Closed
jjanella opened this issue May 3, 2024 · 2 comments · Fixed by #94
Closed

Area2D does not scale with parent #93

jjanella opened this issue May 3, 2024 · 2 comments · Fixed by #94
Assignees
Labels
bug Something isn't working

Comments

@jjanella
Copy link

jjanella commented May 3, 2024

Describe the bug
An Area2D's area does not scale with its parent, while the debug shape visualizer and default Godot physics do scale the area with the parent. Maybe there should be a disclaimer that Area2D's are not scalable as it is not a "Drop-In replacement" otherwise.

To Reproduce
Steps to reproduce the behavior:

  1. Use the Rapier Engine
  2. Have a node with child that is Area2D
  3. Scale the node
  4. Notice the Area2D did not scale (and if the debug shape visualizer is enabled it did scale)

Expected behavior
When the parent scales, so does the child Area2D

Environment (please complete the following information):

  • OS: Arch Linux
  • Version 0.6.18
  • Godot Version 4.2.2
  • Type SIMD

Example project

Insert this code into a Node2D using Rapier physics. Play with the slider to try different scales. Mousing over the sprite should turn it black, however (unless you use default physics) the sprite doesn't properly represent the Area2D, because the Area2D didn't scale. Also notice the debug shape did scale if it is enabled.

extends Node2D

func _ready():
	var p = Node2D.new()
	p.position = Vector2(400, 400)
	add_child(p)
	
	# Area that does not scale as expected
	var a = Area2D.new()
	var c = CollisionPolygon2D.new()
	c.polygon = [Vector2(-100, -100), Vector2(100, -100), Vector2(100, 100), Vector2(-100, 100)]
	a.add_child(c)
	p.add_child(a)
	
	# Sprite to show when a the mouse is in its area
	var s = Sprite2D.new()
	s.texture = preload('res://icon.svg')
	s.scale = Vector2(200, 200) / s.texture.get_size()
	a.mouse_entered.connect(func(): s.modulate = Color(0, 0, 0))
	a.mouse_exited.connect(func(): s.modulate = Color(1, 1, 1))
	p.add_child(s)
	
	# Slider to scale the node
	var v = VSlider.new()
	v.step = 0.01
	v.max_value = 4
	v.value_changed.connect(func(value): p.scale = Vector2.ONE * value)
	v.size.y = 200
	add_child(v)
@jjanella jjanella added the bug Something isn't working label May 3, 2024
@jjanella
Copy link
Author

jjanella commented May 3, 2024

A workaround for this bug would be setting the Area2D's global scale to 1, and mapping its polygon to a properly scaled version of itself.

@Ughuuu Ughuuu self-assigned this May 4, 2024
@Ughuuu
Copy link
Contributor

Ughuuu commented May 4, 2024

The function body_set_transform only takes rotation and position, it doesn't take into account scale. For this to work I would need to change when creating a collider, apply the scale of the body over it. But I would need to be careful with the order of operations to match the one in godot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants