Godot Version
4.4.1.stable
Question
This might sound weird but my goal is to apply rotation to a CollisionShape2D, here’s what I mean: (script at the bottom) via link
I have an enemy which has the shape of a sword. I added code to rotate the sword towards the player, once the player enters the detection Area2D of the sword. Since I added a health bar to the sword, I applied the code that rotates the sword to the Sprite, the HitBox and the collision shape of the sword, not the parent Node which is a CharacterBody2D.
The reason I did this is because if I apply the rotation to the Parent Node, the health bar will rotate as well and that’s not ideal. Everything works as intended, the issue is that the Collision Shape is a Capsule and Capsules originally are vertical shapes. Since my sword enemy is facing to the right (Horizontal position) I had to rotate the CollisionShape2D (capsule) 90 degrees to cover the sword accordingly.
So when I apply the code to rotate the CollisionShape2D(capsule) towards the player, it will reset it’s rotation back to ‘0’ forcing the capsule to stand vertically again. The CollisionShape2D (capsule) will rotate with the sword but the problem here is that, the Sword is facing a Horizontal direction while the CollisionShape2D (capsule) a Vertical direction.
If I try to rearrange and expand the capsule from vertical to horizontal it will turn into a circle. So I thought about storing and applying a 90 degree rotation to the CollisionShape2D, then when the swords starts rotating towards the player, the CollisionShape2d (capsule) will rotate in the same direction as the sprite, I just haven’t figure out how to do that.
I hope this makes sense. Apologies for the lengthy rant, I just wanted to add as much details as possible.
If that was confusing, here’s a better explanation that shows the script: