Passing an objects rotation down through its children
Posted
by
MintyAnt
on Game Development
See other posts from Game Development
or by MintyAnt
Published on 2012-03-24T22:34:47Z
Indexed on
2012/03/24
23:39 UTC
Read the original article
Hit count: 277
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.
© Game Development or respective owner