Passing an objects rotation down through its children
- by MintyAnt
In my topdown 2d game you have a player with a sword, like an old Zelda game.
The sword is a seperate entity, and its collision box "rotates" around the player like an orbit, but always follows the player wherever he goes.
The player and sword both have a vector2 heading. The sword is a weapon object that is attached to the character.
In order to allow swinging in a direction, I have the following property inside sword (RotateCopy returns a copy of the mHeading after rotation)
public Vector2 Heading
{
get { return mHeading.RotateCopy(mOwner.Rotation); }
}
This seems a bit messy to me, and slower than it could be. Is there a better way to "translate" the base/owner component rotations through to whatever component I am using, like this sword?
Would using a rotation MATRIX be better? (Curretnly rotates by sin/cos) If so, how can I "add" up the matrices?
Thank you.