How do I correct the character grid-based movement?

0 favourites
  • 10 posts
From the Asset Store
Hand-animated Sprite Base for isometric game/animation development
  • I'm creating an grid based movement for a tactical based rpg, on paper, my code is fine, but coding was another story.

    Basically, a function moves a stance of an object to the left, first checking if it has no obstacle.

    If there isn't, then a global variable picks the new position(character.X -32 ) and then it starts moving to the left.

    The problem is it never stops, since the object moves not in round pixels. Construct kinda of interpolates the movement and as such, the value of the global variable is never achieved by the object in movement...

    The project is already configured to retro-style.

    What can I do to correct this position?

    Thanks

  • So as long as it doesn't detect an obstacle it continues to go left... sounds like its doing what your asking of it.

    How are you stopping it?

    Have you tried using System:Trigger Once in the event conditions?

  • Couldn't you, instead of "Xdest=Characters.x" use "XDest<Characters.x + 2" (2 or 4 or whatever works)

    then set the Xdest to Characters.x

  • So as long as it doesn't detect an obstacle it continues to go left... sounds like its doing what your asking of it.

    How are you stopping it?

    Have you tried using System:Trigger Once in the event conditions?

    The thing that is wrong is not the collision detection, but the movement by itself.

    The movement input keys only work if the object is not moving. And the movement only happens a single 32pixels at time to the left if there is no offset obstacle 32 pixels to the left of it. This would

    Since it checks for obstacles before moving and the way the game will work, there will be really no need to check for collisions outside of this scope I believe.

    Couldn't you, instead of "Xdest=Characters.x" use "XDest<Characters.x + 2" (2 or 4 or whatever works)

    then set the Xdest to Characters.x

    It didn't work...

    But this gave me an idea, maybe it is the way the function works... perhaps I should use a "while"? I'm gonna try some new ideas.

    But, does anyone know how to disable the pixel interpolation for the movement, so the smallest distance it can travel and detects at the time is 1pixel ?

  • I had this one lying around, might help:

    Smooth grid movement

  • LittleStain

    Really neat example. And the CPU utilization is like 40% less than my code...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • LittleStain - Ok I know you've been hit with this one a lot and I appreciate your time so I'll be quick. How do I make it so the green block can only move once then stop, and then the AI Let's say a purple block takes a turn moving toward the green block position and stop. So the other one cannot move until after the other ones turn. How do I make the AI block do this on it's own?

    Group activate and then deactivate maybe? Is it possible?

    Thanks

  • LittleStain - Ok I know you've been hit with this one a lot and I appreciate your time so I'll be quick. How do I make it so the green block can only move once then stop, and then the AI Let's say a purple block takes a turn moving toward the green block position and stop. So the other one cannot move until after the other ones turn. How do I make the AI block do this on it's own?

    Group activate and then deactivate maybe? Is it possible?

    Thanks

    shouldn't be that hard..

    To create the turns you'd need a switching global variable..

    Based on who's turn it is either the player would move or the enemy..

    you could have the enemy find the path to the player using pathfinding (without diagonals) and have it move in the same way as the player..

  • LittleStain

    switching global variable - Hmmmm I'm not familiar with that I tried a groups with a variable set to 0 group deactivated and 1 group activated. The AI path finding I understand but I can't seem to make either only go one space and stop. I'm using your example as a guide.

    Thanks for your time though.

  • like I said you shouldn't use the pathfinding for the movement..

    on path found just make the enemy move one spot in the direction of the first node of the pathfinding..

    So every time the enemy has his turn, first use pathfinding to find the path to the player, than use the grid movement to move 1 square..

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)