What expressions should i use, to make a sprite move to a random location on the viewport?

1 favourites
  • 10 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • I have been trying for the past hour, and the sprite has the pathfinding and moveto behaviors enabled so I'm not sure what is wrong here :/

  • Hi jknnkla I am adding a couple photos that should achieve what you're trying to do. If you're looking to jump the sprite right to the spot instead of "walking" over to it use the set position instead of move to. If you don't want the angle to change when moving uncheck "Set Angle" in the move to behavior panel. You may also need to tweak your speed to your liking. Hope this helps.

    **EDIT** You can also add the bound to layout behavior so that part of your sprite never goes off screen.

  • Thank you so much! Im working on a strategy game so this revolutionary for me!

  • Rebel Zodiac, do you know how to loop the move to position though?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • jknnkla No problem! Just curious when you say loop the position are you trying to have multiple points that it could be and it cycles through in order? For instance instead of going anywhere in the viewport like the way I set this up you have an A,B,C,D that you set and it either goes in order or chooses a random point out of those. If so let me know because it's totally doable either way.

  • Im thinking that once the sprite finds its location, it finds another random location to run to, hope you can help!

  • jknnkla Oh ok I think I see what you're going for. You can add an "On Arrived" Event so that when the player reaches the first random spot it finds another without needing to be told to I'll attach a photo of this. You're basically adding 1 more event and then just copy/paste the action from before. You can also change the "when space pressed" to "on start of layout" and there are many other mechanics that can branch from this. Let me know if you need anymore help.

  • thank you so much dude!!!

  • is there also a way to use the "Original" expression for moving randomly on the layout? Much appreciated!

  • Hey no problem! So the (OriginalViewportHeight) and (OriginalViewportWidth) are only if you want to contain it to the viewport. I believe if you use "(LayoutHeight) and (LayoutWidth) instead you should get that result. Everything else should stay the same.

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