i have the following code to make my player move:
class Player {
PVector direction;
PVector location;
float rotation;
int speed;
Player() {
location = new PVector(width/2, height/2);
speed =2;
}
void visualPlayer() {
direction = new PVector(mouseX, mouseY);
rotation = atan2(direction.y - location.y, direction.x - location.x)/ PI * 180;
if (keyPressed) {
if ((key == 'w' && dist(location.x, location.y, direction.x, direction.y)>5) || (key == 'w' && key == SHIFT && dist(location.x, location.y, direction.x, direction.y)>5)) {
speed = 2;
location.x = location.x + cos(rotation/180*PI)*speed;
location.y = location.y + sin(rotation/180*PI)*speed;
if (key == SHIFT) {
speed = 5;
}
}
} else {
location.x = location.x;
location.y = location.y;
}
println(speed);
ellipse(location.x, location.y, 10, 10);
}
}
when i press the w key the player moves in the direction of the mouse. but i want to make the player move faster if i press the shift key. but now my player stops moving when i press the shift key... why is this happening?? any suggestions to help me fix this problem are welcome :)