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

CapsuleShape2D does not allow to set programatically Radius and Height #101084

Open
Hector-Flores-Pauner opened this issue Jan 3, 2025 · 1 comment

Comments

@Hector-Flores-Pauner
Copy link

Hector-Flores-Pauner commented Jan 3, 2025

Tested versions

-Reproducible in version 4.3

System information

Windows 11 - Godot Engine v4.3.stable.official.77dcf97d8 - OpenGL API 3.3.0 NVIDIA 546.18 - NVIDIA GeForce RTX 4060 Laptop GPU

Issue description

When you try to set up CapsuleShape2D programatically, it does not allow you to set Radius and Height at the same time, if you set the Radius first, then it will be overriden when setting the height later, or vice-versa, if you set the Height first, it will be overriden when setting the Radius later in a way that Height = 2*Radius, having a final circular collisionShape.

Steps to reproduce

-Set a basic 2D Scene containing an StaticBody2D as parent, and Sprite2D and CollisionShape2D as children.
-For this issue, Sprite can be whatever (or even unnecesary, I am just replicating the configuration of the scene I created).
-Set the CollisionShape2D to be a CapsuleShape in the editor.
-Create the following script for the StaticBody2D:

extends StaticBody2D

# Instantiating the Sprite2D and the CollisionShape2D
@onready var sprite: Sprite2D = $Sprite2D
@onready var collision_shape: CollisionShape2D = $CollisionShape2D

# Setting the initialization of the Scene
func _ready() -> void:
	configure_col_shape()

# Setting the texture and the CollisionShape from the Resource
func configure_col_shape():
	# Configura el CollisionShape2D
	if collision_shape and collision_shape.shape is CapsuleShape2D:
		collision_shape.shape.radius = 100
		collision_shape.shape.height = 20
		print("Radio: ", collision_shape.shape.radius, " Altura: ", collision_shape.shape.height)

-According to what happened to me, Collisionshape.shape.radius should be equal to 10 and Collisionshape.shape.height should be equal to 20.

Minimal reproduction project (MRP)

I do not have right now an MRP, but if instructions above are followed, the bug is easily replicable.

@aXu-AP
Copy link
Contributor

aXu-AP commented Jan 4, 2025

I think this is what's happening: a capsule's radius cannot be more than half of height (in which case the shape is a circle). Setting height limits the radius to a correct value (and vice versa, if you test your code but switch the order, height should be 200). Try setting these values in editor, you will observe the same result.

Note that this differs from Godot 3, where height referred to the center part of the capsule. I guess that was unintuitive and therefore was changed to current behaviour, where height is the total height (but it makes radius and height somewhat interdependent).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants