I am trying to set up a simple bow and arrow game. When the arrow hits the enemy body, the arrow's body is deleted and the arrow sprite continues to update, keeping the position correct in relation to the enemy it hit. Picture an arrow sticking into a body and that body still rotating and moving. My problem is that the rotation is completely wrong when the enemy rotates. I know how to do this in 3d with matrix transformation but I can't seem to figure it out in 2d with Cocos.
Here is my method.
- I save offset at which the arrow hit the enemy.
- Every frame, I make the rotation of the sprite match the rotation of the enemy.
- Then, I apply the offset I took initially which is where the arrow hit the enemy.
When they rotate, they rotate about their respective anchors and I am wondering if I need to set the anchor of the arrow to the center of the sprite. Does anyone know of an easy way to do this. If not, I will try to create an algorithm where the anchor is set to the offset divided by the width and height of the sprite image hopefully giving me the correct anchor values.
Then I assume I need to reposition the sprite.
Does anyone have a simpler way to do this?