if (key == ConsoleKey.A) { // Move left (strafe) double perpDirX = -dirY; double…
- User
if (key == ConsoleKey.A) { // Move left (strafe) double perpDirX = -dirY; double perpDirY = dirX; if (IsPositionEmpty(posX + perpDirX * moveSpeed, posY)) posX += perpDirX * moveSpeed; if (IsPositionEmpty(posX, posY + perpDirY * moveSpeed)) posY += perpDirY * moveSpeed;
EnsureMapAroundPlayer();} if (key == ConsoleKey.D) { // Move right (strafe) double perpDirX = dirY; double perpDirY = -dirX; if (IsPositionEmpty(posX + perpDirX * moveSpeed, posY)) posX += perpDirX * moveSpeed; if (IsPositionEmpty(posX, posY + perpDirY * moveSpeed)) posY += perpDirY * moveSpeed;
EnsureMapAroundPlayer();}
modify these to ensure the strafing is relative to the player yaw. only provide the code snippets needed to edit to achieve this.
- Assistant
To make strafing relative to the player's yaw, update the perpendicular direction calculations using the
yawangle. Replace the existingperpDirXandperpDirYassignments in both theAandDkey blocks with the following snippets:For strafing left (
ConsoleKey.A):// Move left (strafe) relative to yaw double perpDirX = Math.Cos(yaw - Math.PI / 2); double perpDirY = Math.Sin(yaw - Math.PI / 2);