Hi! Can anyone enlighten me on how to fix this issue?
This 2 issue being shown on the video.
1. I can move the character either by Mouse or keyboard, however I'm having an issue with the keyboard movement if it hit a non-walkable area (using a 1280x720 resolution and background), it will just pass the nonwalkable area.
2. I change the background to bigger one, that way I can try the parallax movement, and now with wither the Mouse or Keyboard I encounter an issue, everything will stop moving when it hit the nonwalkable area, or a solid(character) seems like it lagged and then it will pass the nonwalkable area.
Thanks in advance...
Are you using the KeyboardMovement module? Or custom code?
Quote from: Khris on Sun 10/05/2020 20:02:31
Are you using the KeyboardMovement module? Or custom code?
Yes its a custom code.. not a good one
if (IsKeyPressed(eKeyW))
{
tempAmount = 5;
cPlayer.y = cPlayer.y - tempAmount;
cPlayer.Walk(cPlayer.x, cPlayer.y-5, eNoBlock);
}
else
{
if(tempAmount>0)
{
tempAmount--;
cPlayer.y = cPlayer.y - tempAmount;
}
}
if (IsKeyPressed(eKeyS))
{
tempAmount2 = 5;
cPlayer.y = cPlayer.y tempAmount2;
cPlayer.Walk(cPlayer.x, cPlayer.y 5, eNoBlock);
}
else
{
if(tempAmount2>0)
{
tempAmount2--;
cPlayer.y = cPlayer.y tempAmount2;
}
}
if (IsKeyPressed(eKeyA))
{
tempAmount3 = 5;
cPlayer.x = cPlayer.x - tempAmount3;
cPlayer.Walk(cPlayer.x-5, cPlayer.y, eNoBlock);
}
else
{
if(tempAmount3>0)
{
tempAmount3--;
cPlayer.x = cPlayer.x - tempAmount3;
}
}
if (IsKeyPressed(eKeyD))
{
tempAmount4 = 5;
cPlayer.x = cPlayer.x tempAmount4;
cPlayer.Walk(cPlayer.x 5, cPlayer.y, eNoBlock);
}
else
{
if(tempAmount4>0)
{
tempAmount4--;
cPlayer.x = cPlayer.x tempAmount4;
}
}
tempAmount = 5; ///the movement speed, and its used to decrease the movement slowly once char stop, to slow down the strong halt movement on the map.
cPlayer.y = cPlayer.y - tempAmount; //this makes the char move, I think that the nonwalkable area cannot stop this
cPlayer.Walk(cPlayer.x, cPlayer.y-1, eNoBlock); // the actual way to make char walk, but in here its just makes the char use the animation
anyway to code something like this?
that will pushback character
if((charmove up == true)&&( itHitNowalkable)
{
cPlayer.y = cPlayer.y + 5;
}
I think I was able to fix the issue for the keyboard movement, it no longer pass the nonwalkable area, its just the mouse issue now which only occur on if its a big background, but I'm not going to use mouse for movement so I think its solved, thank you so much!.
This is the code I used inside function repeatedly_execute() in Global script :
//////////// keyboard movement
if (GetWalkableAreaAtRoom(player.x, cPlayer.y-6) != 0)
{
if (IsKeyPressed(eKeyW))
{
tempAmount = 5;
cPlayer.y = cPlayer.y - tempAmount;
cPlayer.Walk(cPlayer.x, cPlayer.y-1, eNoBlock);
}
}
if (GetWalkableAreaAtRoom(player.x, cPlayer.y+6) != 0)
{
if (IsKeyPressed(eKeyS))
{
tempAmount2 = 5;
cPlayer.y = cPlayer.y + tempAmount2;
cPlayer.Walk(cPlayer.x, cPlayer.y+1, eNoBlock);
}
}
if (GetWalkableAreaAtRoom(player.x-6, cPlayer.y) != 0)
{
if (IsKeyPressed(eKeyA))
{
tempAmount3 = 5;
cPlayer.x = cPlayer.x - tempAmount3;
cPlayer.Walk(cPlayer.x-1, cPlayer.y, eNoBlock);
}
}
if (GetWalkableAreaAtRoom(player.x+6, cPlayer.y) != 0)
{
if (IsKeyPressed(eKeyD))
{
tempAmount4 = 5;
cPlayer.x = cPlayer.x + tempAmount4;
cPlayer.Walk(cPlayer.x+1, cPlayer.y, eNoBlock);
}
}
Try this instead:
// above repeatedly_execute
int olr, oud;
void HandleWalking() {
int lr = IsKeyPressed(eKeyD) - IsKeyPressed(eKeyA);
int ud = IsKeyPressed(eKeyS) - IsKeyPressed(eKeyW);
if (lr != olr || ud != oud) {
if (lr == 0 && ud == 0) player.StopMoving();
else player.WalkStraight(player.x + Room.Width * lr, player.y + Room.Width * ud, eNoBlock);
olr = lr; oud = ud;
}
}
// inside repeatedly_execute()
HandleWalking();
Quote from: Khris on Mon 11/05/2020 23:17:57
Try this instead:
// above repeatedly_execute
int olr, oud;
void HandleWalking() {
int lr = IsKeyPressed(eKeyD) - IsKeyPressed(eKeyA);
int ud = IsKeyPressed(eKeyS) - IsKeyPressed(eKeyW);
if (lr != olr || ud != oud) {
if (lr == 0 && ud == 0) player.StopMoving();
else player.WalkStraight(player.x + Room.Width * lr, player.y + Room.Width * ud, eNoBlock);
olr = lr; oud = ud;
}
}
// inside repeatedly_execute()
HandleWalking();
Thank you so much! I will try it and keep this code.