R
Robin326
Guest
Hello devs,
for some days now, I'm trying to find a solution for the following two problems, which I encounter in with my player movement. First of all, my code:
The code lets the player object move towards or in opposite direction of the cursor and lets it strafe to the left and right in a circular line. Top-Down shooter style.
First problem:
How can I strafe +/- 90 degrees from the player object facing direction, without using the circular line?
Second problem:
As soon as the player object collides with a wall, it stops. How can I make it slide along the walls?
I hope you guys can help me out.
Robin
for some days now, I'm trying to find a solution for the following two problems, which I encounter in with my player movement. First of all, my code:
Code:
/// Player movement
// Movement direction
direction = point_direction(x, y, mouse_x, mouse_y);
// Facing direction
image_angle = direction;
// Move foreward
if keyboard_check(ord('W')){
speed = player_speed;
}
else speed = 0;
// Strafe left
if keyboard_check(ord('A')){
x -= lengthdir_x(player_speed, direction - 90);
y -= lengthdir_y(player_speed, direction - 90);
}
// Strafe right
if keyboard_check(ord('D')){
x -= lengthdir_x(player_speed, direction + 90);
y -= lengthdir_y(player_speed, direction + 90);
}
// Move backwards
if keyboard_check(ord('S')){
x -= lengthdir_x(player_speed * 0.75, direction);
y -= lengthdir_y(player_speed * 0.75, direction);
}
// Stop player when cursor position is reached
if point_distance(x, y, mouse_x, mouse_y) < 5{
speed = 0;
exit;
}
First problem:
How can I strafe +/- 90 degrees from the player object facing direction, without using the circular line?
Second problem:
As soon as the player object collides with a wall, it stops. How can I make it slide along the walls?
I hope you guys can help me out.
Robin