How do i make this square move?

In the image attached I have a black square sitting inside a red box my question now is how would I make the black square move randomly inside of the box? All I have managed so far is making it move randomly inside the box but also making it look quite hideous and it also didn’t work quite as intended

What does it represent? It would help us make better suggestions. If you post a screenshot of what you have, we might be able to help you improve it.

How do you want it to move? Is it moving diagonally? Will it pause from time to time? Will it move at a constant speed?

My apologies. I want to create a top-down management game. The black square represents the NPC, and the red barrier is the designated field it moves within. I want it to move randomly within that field until it’s selected. Once selected, it will move from point A to point B, wait for, for example, one second, then set a new point B and repeat this cycle.

No apologies needed. Are there going to be obstacles?

Without obstacles you could tween from place to place directly. With obstacles you could use the pathfinder behavior.

You could use use either random x, y using the random in range expression or add objects as a sort of waypoint.

The random method is easier unless there are obstacles. If there are obstacles then you need to test the destination of the random numbers and then pick a new number if the location isn’t reachable.

With a hidden way point object you can use the pick a random object to target a position and use the objects x, y for either the tween or pathfinder behavior. You would know the location was always valid.

There are so many ways to do things. One way is not necessarily better than another. We use what we know until we learn a better way.

The tween behavior has a tween has finished playing and the pathfinder has reached destination. They would allow it to pick a new location for the NPC.

1 Like

that seems to work great thank you :slight_smile:

1 Like