Move back desired space, fighting game.

Hey everyone

So I am creating a fighting game and have special moves that are executable.

I want the player that executes the move to move back a required distance from the opposing player so the animation plays correctly.

for (int i = 0; i < charM.players.Count; i++)
{
enStates = charM.returnOppositePlayer(charM.players[0]).playerStates;

float konquerDistance = Vector3.Distance(transform.position, enStates.transform.position);
}

I have a distance check which returns me the current distance between each player but am struggling to think of how to write the code to move the players apart.

Thanks

If the player is facing the opoonent, simply move it in the direction of

-transform.forward

to separate them

In fighting games usually such moves are allowed to execute when distance between fighters falls into some predefined range, otherwise move won’t start. For instance it will just play fail animation or even do nothing if you try to execute grapple while being away from opponent. And if the animation requires exatct distance, then bot player are moved toward required distance using linear interpolation during few first frames of animation. In unity there’s Vector3.Lerp to interpolate vectors.

Hey thanks for the responses, yeah i’m ray casting to figure out the executable distance, they just need to move a little bit back in case the move is executed at too close of a range.

I’ve figured it out by getting the current Vector3 of the character executing the move comparing it with the other and lerping it back like you said :slight_smile: