Sign in to follow this  
mickeyren

2D game, how to calculate position of staff

Recommended Posts

Hi Please see screen shot - so depending on the mage's position, the staff would be in different direction, angle and position as well.   I would like to emit a fireball from the mage's staff - it seems I'm puzzled as how to calculate the position so the fireball emits correctly from the tip of the staff. Thanks

Share this post


Link to post
Share on other sites
Well, as I can see you already know how to calculate the player facing vector since the character do turn around. Your staff is already included in the mage picture. I don't understand the question, since you could simply use the same for the fireball and add a short distance? ( FireballSpawnPos = MagePos + FacingVec * DistanceFromMage).

Share this post


Link to post
Share on other sites
Is that 2d or 3d?

Or, a better question is:

Is the player only allowed to face, say 4 different directions? If so, figure out the offset you're looking for for each orientation and pick the right one depending on which direction theyre facing

For 2d sprite based stuff it's helpful to set up reference points for your sprites. What I mean by that is you store a bunch of metadata for the sprite - find the pixel offset of the point of interest (say "firepoint", or "base") for each version of the sprite (for each direction, and each frame of animation), and then when you want to figure out where to spawn a projectile, look up the offset based on the orientation and which frame of animation it's in, and you have your value

You can use a reference point system like this to attach objects together - for example, put a reference point on character's hands, and put a reference point on each object they can hold, and then in code when you want to have the character holding some object, you just line up the reference points and the object will follow the hand

Share this post


Link to post
Share on other sites
Quote:
Original post by Dunge
Well, as I can see you already know how to calculate the player facing vector since the character do turn around. Your staff is already included in the mage picture. I don't understand the question, since you could simply use the same for the fireball and add a short distance? ( FireballSpawnPos = MagePos + FacingVec * DistanceFromMage).


thanks guys - that seems to be the formula that I forgot and was looking for! All's well now Merry Christmas!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this