How do I…
I want to move the player to different squares/grids. Let’s call them Grid_1, Grid_2, Grid_3 etc.
The player has a variable called “Current Position” starting at zero.
Is there a way that I can use “Move towards object with force” and replace the number in the grid name with the current position variable?
For example: Move to Grid_“player.variable(CurrentPostion)”
I hope I explained this properly, not really even sure how to search for something similar, and I hope I didn’t break any forum rules, this is my first post here… Hello!
Welcome CharlieMcGruff. There are many ways to do it. A little context will help you get a better solution. To my knowledge, you can’t target an object by its name but you can use an object variable. You could also use its location, pick a random object, cast a ray among others.
Conditions work like filters. All objects that meet the condition(s) get picked and any actions will affect them. There’s generally a better way that doesn’t require object variables. But each situation is different and sometimes it is the best way.
example with a variable and button.
There are also a lot of ways to move an object to another object. You could use force or a tween or the pathfinder behavior among other behaviors and extensions.
So basically, I am trying to do a Snakes and Ladders kind of movement, where dice rolls will add to the current position of the player and then the player will move to the corresponding grid/square.
I am really new to GDevelop and gamedev in general, so I am trying to use the most basic thing I can think of…
That’s fine. We all start with object variable. I still use them. In your case. It would work well. Check the value of the tile the player is on using a collision and then add the number of spaces.
try me: click the button to move
source: (click green [code] and download zip. then unzip and open the json with Gdevelop)
This uses a group but you could use instances with different animations. The objects are in a group named group. The player object has the tween behavior. It numbers the objects at the start but you can assign them in the editor. Note: it numbers them in the sequence that they’re added to the scene.
edit: the mod() expression is used so when it reaches the last id number it restarts at zero.
Thanks! This at least gives me a direction to look ine
Thanks for all your effort man, that’s great!