Jump to content
  • Advertisement
Sign in to follow this  
Senor Beer

Movement in fighting game (XNA)

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm having some trouble moving two of my characters in a multiplayer fighting game for XNA. I'll post the relevant code here:

public void UpdatePlayerOne(PlayerIndex thisPlayer, Vector3 opponentPosition, float distance)
        {
            EngineResources.game.Window.Title = distance.ToString();

            //Very smooth, works apart from strafing
            position.X = (float)(opponentPosition.X + (distance * Math.Cos(MathHelper.ToRadians(strafeAngle))));
            position.Z = (float)(opponentPosition.Z + (distance * Math.Sin(MathHelper.ToRadians(strafeAngle))));


            playerMatrix = Matrix.CreateTranslation(position);
        }


        public void UpdatePlayerTwo(PlayerIndex thisPlayer, Vector3 opponentPosition, float distance)
        {
            position.X -= GamePad.GetState(PlayerIndex.Two).ThumbSticks.Left.X;
            position.Z += GamePad.GetState(PlayerIndex.Two).ThumbSticks.Left.Y;

            playerMatrix = Matrix.CreateTranslation(position);
        }


Both of these methods are in the Update section, PlayerOne getting updated first and then player2. The problem being that when I comment out the 'UpdatePlayerTwo' method, everything moves fine (except for player two ofc), but when I include it they both fly off the screen to ridiculous positions. I think the problem is that they both use the same 'distance' variable to move (which is literally the distance between the two of them). So when player two tries to move closer to player one, player one also moves towards player two without me using his controls. This is all circle trigonometry that I dont fully understand. Can anybody shed some light on this problem? If you need me to post anymore code or clear anything up just please ask! Thanks in advance --Senor Beer

Share this post


Link to post
Share on other sites
Advertisement
Sorry for the double post but I've just noticed something.

The code I'm using to move player one is circle trigonometry (i.e. working out his position based on the center of a circle (the opponent), the distance and the angle he moves by), and because of this when I use player two's basic movement, player one essentially mirrors him to stay on the outside of this circle.

Don't know if that helps, but I essentially wanted him to sit tight when player two moves, not be dragged around the map :P

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!