Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | PerduGames | |
Old Version | Published before Godot 3 was released. |
I wanted to change the size of CollisionShape2D during the game, for example: I have a character that can lower, so this causes your Shape2D in y to decrease a bit and the origin I believe has to go down too. How can I do this? If Shape2D shrinks is actually the correct way to do this, since it is as the child of a KinematicBody2D.
Up 1:
I thought of two ways to do this:
1 - Create a new “Shape” and transfer it to “CollisionShape2D”.
2 - Use “set_shape_transform” from my “KinematicBody2D” which asks me for two information “set_shape_transform (int shape_idx, Transform2D transform)”, I understood that “int shape_idx” in my case would have to be 0, since there is only one “CollisionShape2D”, so 0 would be the first one I would find, if there were two “CollisionShape2D” and I wanted to change the second of the order of the hierarchy, it would have to be 1, am I right?
As for the “Transform2D transform” I saw in the documentation that it is a Matrix32, so I thought of doing so:
Var m = Matrix32 ()
M [0] = Vector2 (0, 0) # X
M [1] = Vector2 (0, 0) # Y
M [2] = Vector2 (0, 0) # Origin
I do not quite understand how I would decrease here, I imagine I would have to use “get_shape_transform” to get the current “Transform2D”, and so change only the y where I want, am I right here?
And I see in the hierarchy the “CollisionShape2D”, has “Node2D”> “Transform”> {“Pos”, “Rot”, “Scale”}, is not there a way to directly change those? Example, something like:
Get_node ("CollisionShape2D") Node2D.Transform.Pos = Vector2D (0, 0)
Get_node ("CollisionShape2D") Node2D.Transform.Scale = Vector2D (0, 0)
Up 2:
I tried to do this:
var transform = get_node("CollisionShape2D").get_transform()
var oldScale = transform.get_scale()
transform.scaled(Vector2(oldScale.x, oldScale.y - 0.5))
get_node("CollisionShape2D").set_transform(transform)
But there is no change in Shape, where am I going wrong? And this is the best way to do this?