How do I prevent units from moving through solid walls?

0 favourites
  • 7 posts
From the Asset Store
SCI-FI Units SFX contains 456 sounds With this pack, you can voice almost all the units in your sci-fi strategy game
  • I am using the built in pathfinding for my Turn Based tactical game.

    Here is my capx

    https://www.dropbox.com/s/3iqjnrt6csg14lj/RebelStarShared.capx?dl=0

    The units move along the path but they cut corners.

    The tile map is 32x32 I have set the cellsize of the pathfinding to 16 or 32, and everything else I could think of, yet they units still cut corners straight through the "solid" walls. I have also tried other settings like disabling diagonal movement, however no improvement.

    I don't quite understand why there is this problem and why it cannot be set to obey the solid walls. I know there is another pathfinding plugin but first glance it looks more complicated to use so I was hoping to see if I could acceptable results from what I have built already.

    The game is a work in progress and I have no commercial aspirations for it, simply a hobby project. However, please do not use my code for yourself without talking to me first. Thanks.

  • Hey man,

    An easy way to do it would be to give your player the 8 direction behavior and set rotation and standard controls to none.

    It seems to work after that.

  • Since your player has no "collision detection for solids" Giving it an 8 direction will

    Also, I would work on the detection box and maybe enlarging the size of the doorways so you have a smoother path finding animation

  • HI ryrydawg I am not sure I follow. The 8 direction behaviour would be a possibility for the player but I am not sure how that would solve the issue for the CPU player.

  • HI ryrydawg I am not sure I follow. The 8 direction behaviour would be a possibility for the player but I am not sure how that would solve the issue for the CPU player.

    I have uploaded the new version

    Changes :

    • Made the player and CPU player smaller to avoid the collision box catching on corners
    • Set the cpu player and human player to 8 direction so that they have a collision with solid objects property.

    Note that the size of the cpu and player sprites were changed only on the layer. Not the actual sprite. You can play around with the sizes to get the perfect fit.

    As I said before, there are probably other ways to solve your problem but the would be the quickest

    https://onedrive.live.com/redir?resid=E ... ile%2ccapx

    You could also just scrap everything I just said and simply add a solid behavior to the player and CPU player. That seems to work too but the movement looks too fake

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Nice result That look much more acceptable. Sometimes the player gets caught in certain spots but I may be able to work that out. I will need to check it closer in the morning.

    R

  • czar

    Awesome! If you figure it out, please post it here

    Keep well

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