# 2D game, how to calculate position of staff

This topic is 3273 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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 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 on other sites
Quote:
 Original post by DungeWell, 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!

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
13
5. 5
frob
12

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633665
• Total Posts
3013239
×