# Movement in fighting game (XNA)

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

## 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)
{

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 on other sites
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

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 13
• 9
• 12
• 9
• ### Forum Statistics

• Total Topics
631438
• Total Posts
3000073
×