Public Group

An xna tutorial i need to find?

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

Recommended Posts

I am trying to find a tutorial on xna that answers a basic question that I can't complete. My goal with this is to have a sprite rotate(top down view of a person) and launch a sprite from its center. I have that part but my only problem is that I want the sprite to launch from the front of the sprite no matter what direction it is turned(So it can launch in a 360 degree way). I searched google and everywhere else and could not find this? Any ideas. Thanks

Share on other sites
Are you talking about like shooting a sprite bullet from a ship sprite? For example, if the ship is aiming North and turns left and is aiming SouthWest you want to be able to shoot where the sprite is pointing (to the SouthWest)?

Share on other sites
Yah, like if the is vertical and turns left I want the sprite to launch left instead of forwards. But like you said with some greater degree of choice like southwest instead of just south or west.

Share on other sites
You'll have to take the ship's rotation into account. The rotation is defined by a Matrix, so you should be able to just multiply the rotation matrix by a unit vector pointing forwards (i.e. Vector3(0,0,-1) ). This calculation will give you a forward vector in the current direction of the ship. The final step is to just have the bullet travel along that forward vector.

Edit:
Sorry, I just realized that you were referring to a 2d sprite (it's a 3D development habit). You should be able to apply the same principle of having a, now, 2d vector pointing in the direction of the positive y-axis, and use that as the forward vector.

Hope it helps!

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 14
• 46
• 22
• 27
• Forum Statistics

• Total Topics
634047
• Total Posts
3015230
×