How do I pick a tilemap tile nearest to a sprite?

0 favourites
From the Asset Store
Each tile 64 by 64 pixels - Ultimate Tile Set for your awesome games
  • imps are digging tiles 1 behind the front line. they wont unless its the only option.

    t only happens occasionally. but, its a bug, maybe you faced?

    m using, pick nearest, find path. but despite it being an >unreachable route, they do it anyway.

    Sorry i dont quite understand what you mean. I dont recall an issue with digging. There was a bug with Line of sight but was fixed.

  • BaconSwagg

    youtube.com/watch

    code:

    for each impbase:

    is not boolean working

    is not boolean targetted

    pick become tile, become tile dig=1

    becometile. pick nearest imp base.

    (so if the imps dont have a job, they arent currently moving to something, and the tile is selected to be dug)

    becometile.x+radius*((impbase.x-becometile.x)/sqrt((impbase.X-becometile.X)^2+(impbase.Y-becometile.Y)^2))

    impbase.Uidcheck: set to become tile UID

    set boolean working true

    set boolean targetted true.

    the path finding code is explained in the video. i had another topic where i explain it. but, it just checks the center point of the tile, and calculates the closest point on the circumfrance to the imp.

    on arrived. impcheckuid>0 set digging boolean true.

    then the dig code is just do an animation based on a timer. and do damage to the becometile that has UID= impbase.uid check.

    just want to add, in the video, the imps stop when they cant reach the block to dig. they will continue to do other jobs when unselecting the block.

    priority is to drop off gold they have when full. dig, and then claim ground

  • So far it looks like it's working, but they can select blocks that should be too far away. Maybe making the radius a little smaller will fix it? I don't know if that's the best solution, but it might work.

  • BaconSwagg yeah, i knew it may be in issue. its why i set the radius as a GV. maybe it just needs playing around with the figure. i tried a little, too small and they cant target the block, too big, and they can target further blocks.

    the blocks are 96x96 : radius should be 48! and that should barely let them get to the block... yet on 16, it seemed to be the perfect figure.

    i may go back to the drawing board at all on it... trying to rule out using raycasting with barely any experience on it.

    maybe i could give the blocks pathfinding... they wont move, but if they can find a path, the imps can target it.

    either way, the conversation on it helps me think, so its appreciated

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • becometile.x+radius*((impbase.x-becometile.x)/sqrt((impbase.X-becometile.X)^2+(impbase.Y-becometile.Y)^2))

    What does this do? Is it for checking if the block is close enough to the imp? If so then I would just check if the distance between them is less than the radius.

    distance(imp.x,imp.y,block.x,block.y) < radius

  • it checks a position on a circle around the block.

    in effect they pick the closest place they can go to from any angle. its for finding the path.

    distance(imp.x,imp.y,block.x,block.y) < radius is good to activate the digging when they are close enough. but, i just assume they are close enough on arrived, and rotrate them to the block on uid check to start digging.

    im getting them to walk to a block that is a solid. so its x,y coords are impossible to get to and i had to use radius

  • Interesting, I think you could maybe check if the block is too far away. So if the distance is greater than an amount, stop the pathfinding. I also think that having a list of which blocks are available for mining and then picking a random or the closest one out of that list may make this easier.

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