Hi
I'm making a platformer and I use 0 and 1 to 'k' for simple gravity
int k = GetWalkableAreaAt (cCharacter.x-GetViewportX(), cCharacter.y-GetViewportY());
Also I use KeyboardMovement module too for combine walking and turn character.As this module don't support out of walkable area I use this code:
if ((IsKeyPressed(eKeyLeftArrow)==true)&&(IsKeyPressed(eKeyRightArrow)!=true)) cCharacter.x-=1;
if ((IsKeyPressed(eKeyRightArrow)==true)&&(IsKeyPressed(eKeyLeftArrow)!=true)) cCharacter.x+=1;
Everything is ok but if I press left or right and falling to down and stand up without release left or right key, character glide without walking and when release keyboard it's fine and character continue walking without glide.
How can i fix it?
I'm Appreciate for any help
I'm certainly the last person on this forum who can give advice.
But a single boolean could make the difference..
bool on_ground = true;
Sorry but I used boolean too.My main problem is when press left or right key without release it after falling and stand up.that I have glide instead walking.If I release key anythings is normal.
I think I have to disable line 1 and 2 when I have play animation falling and stand up and after that I enable it.or disable left or right key when I have falling or stand up. But unfortunately I don't know how can I write it.
Maybe add a view check?
Quote from: Mehrdad on Wed 08/10/2014 16:20:09
I think I have to disable line 1 and 2 when I have play animation falling and stand up and after that I enable it.or disable left or right key when I have falling or stand up. But unfortunately I don't know how can I write it.
Hello Mehrdad. Try using
Character.Animating Property. If I understand it correctly, this might be what you're looking for.
E: If you don't mind, can you please post that part of the script where the character performs the animation?
Yes of course.This is my code
KeyboardMovement.SetMode(eKeyboardMovement_Pressing);
}
bool l = true;
bool faceM = 1; // direction left or right
// put anything you want to happen every game cycle in here
function repeatedly_execute()
{
int k = GetWalkableAreaAt (cCharacter.x-GetViewportX(), cCharacter.y-GetViewportY());
//Left and Right
if ((IsKeyPressed(eKeyLeftArrow)==true)&&(IsKeyPressed(eKeyRightArrow)!=true)){ cCharacter.x-=1;faceM=0;}
if ((IsKeyPressed(eKeyRightArrow)==true)&&(IsKeyPressed(eKeyLeftArrow)!=true)){ cCharacter.x+=1;faceM =1;}
//Falling and Stand up
if ((k == 0)&&(l==true)){if(faceM==1){ cCharacter.LockView(2);
cCharacter.Animate(1, 0, 0, eBlock, eForwards);cCharacter.UnlockView();l=false;}}
if ((k == 0)&&(l==false)){if(faceM==1){ cCharacter.LockView(2);
cCharacter.Animate(2, 0, 0, eBlock, eForwards);cCharacter.y+=10;cCharacter.UnlockView();}}
if ((k == 1)&&(l==false)) {l=true;if(faceM==1){cCharacter.LockView(2);
cCharacter.Animate(3, 0, 0, eBlock, eForwards);cCharacter.UnlockView();cCharacter.Walk(cCharacter.x+2, cCharacter.y, eBlock);}else if(faceM==0)
{cCharacter.LockView(2);
cCharacter.Animate(10, 0, 0, eBlock, eForwards);cCharacter.UnlockView(); cCharacter.Walk(cCharacter.x-2, cCharacter.y, eBlock);}}
if ((k == 0)&&(l==true)) {if(faceM==0){ cCharacter.LockView(2);
cCharacter.Animate(8, 0, 0, eBlock, eForwards);cCharacter.UnlockView();l=false;}}
if ((k == 0)&&(l==false)){if(faceM==0){ cCharacter.LockView(2);
cCharacter.Animate(9, 0, 0, eBlock, eForwards);cCharacter.y+=10;cCharacter.UnlockView();}}
loop 1,2,3 is: ready to falling,fall,stand up for right
loop 8,9,10 is:ready to falling,fall,stand up for left
OK
Problem solved but not complete.That take many times.It's enough for me at the moment.
And another question about moving.I used walkable area with 'int k' for horizontal obstacle(please see first post). Is it possible use same walkable area for left and right obstacle? My mean is character go to stop when collision with walkable area.
appreciate for any help or suggestions
Quote from: Mehrdad on Fri 10/10/2014 07:02:19
My mean is character go to stop when collision with walkable area.
appreciate for any help or suggestions
Wouldn't regions work?