#Help with 3D fighting game-like movement

1 messages · Page 1 of 1 (latest)

cloud ridge
#

Hello, sorry this is my first post on here so if there's a format I'm not following I apologize and will correct it.

I had a question about how to handle 3D strafing around a target, similar to Tekken or something like Soul Caliber.

The enemy is always locked on so it's not a worry about toggling lock on, and the camera will adjust to the movement to keep both characters in view so I'm not too worried about the camera either.

I got the forward and backward moving working but no matter what I try I can't seem to get the player to strafe around the enemy character in a circle when pressing the "up" or "down" input.

I'm using MoveAndSlide() and am just at a loss for how to properly set the velocity so that the character moves around the enemy in a circle while maintaining the original distance (so the radius) between them and the enemy.

Please let me know if you have any advice on how to do this. I would greatly appreciate the help.

smoky zodiac
#

Target point is vector between the opponent and the moving player rotated by some number of degrees, then move towards that.

prisma crest
#

Get the direction to the enemy, then rotate it 90 degrees to a side and move towards that rotated vector.

Example:

var towards_target: Vector3 = global_position.direction_to(enemy.global_position)

var strafe: Vector3 = towards_target.rotated(Vector3.UP, PI/2)

Since this is a fighting game, replacing velocity with this vector (plus the speed) is probably good enough.

#

Vector3.UP is the vector around which the object rotates, in this case it basically acts like a strip pole as it points straight upwards.

PI/2 is 90 degrees in radians.
-PI/2 would be 90 degrees counter clockwise.

cloud ridge
# prisma crest Get the direction to the enemy, then rotate it 90 degrees to a side and move tow...

sorry, thanks for your advice.
This does seem to sort of work, similiar to something I had tried before, but it ends up with an initial straight line movement that eventually rounds out to a circle and also that circle grows bigger each loop around the enemy.

Any suggesstions how to fix these issues?

current code is like so, again thank you very much for your advice:

    Vector3 towardsTarget = GlobalPosition.DirectionTo(enemyCharacter.GlobalPosition);
    Vector3 strafe = towardsTarget.Rotated(Vector3.Up, (float)(Math.PI/2));

    if (strafeSpeed != 0)
    {
        velocity = strafe * movementSpeed * strafeSpeed;
        velocity.Y = 0;
    }