How do I set random position to move on?

0 favourites
  • 7 posts
From the Asset Store
Vector illustration of a UFO with an alien in three different positions.
  • Hello i was wondering if is there any chance to make my enemyobject with pathfinder chosing a random position on a map and then walk there, also to find a location where is no object so he is not going to be stucked in the wall for ever.

    Example: my player is in left top corner and other objects are enemies, they are now set to find my position and follow, but at some time i only want them to find random point on a map and walk to it.

  • Assuming you're using a tilemap.

    The first step is to pick a random point to check if it is valid or not. You'll need to save this point to a instance variables, since if it is valid after checking we'll want to move to that spot.

    First set variables targetx and targety to round(random(layout.width)) and round(random(layout.height)).

    Use system compare two values to check if tile at that location is valid. tilemap.tileat(positiontotilex(self.targetx)),positiontotiley(self.targety)) = valid tile.

    If it is, then set pathfinding move to targetx and targety. Else run the event/function again with a new random target.

  • Iam actually using tilled background, doest that make a difference? Im very new into Construct 3 and still learning lots of stuff here. If there is no any difference, can we go step by step? I dont know what type of variable should it be either where to put the round function.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Okey i figured it out

    i directly typed in X cordination box that code, a bit different than yours but it helped me to go on a right path, thank you!

  • If you're not using tilemap, you'll want to check if an object (wall) is overlapping at that random point instead.

  • It seems that pathfinder automatically find only the reachable points tbh.

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