0
\$\begingroup\$

I'm making a 2D rpg and I want the character to move with the mouse, ie the user clicks and then the character moves to that location. How do I accomplish this?

\$\endgroup\$
  • \$\begingroup\$ Lol that question didn't even get a legitimate answer \$\endgroup\$ – slayer Oct 28 '14 at 22:51
  • \$\begingroup\$ This question has already been answered a lot and OP didn't provide what he has tried. That's what I wanted to show. \$\endgroup\$ – Heckel Oct 28 '14 at 22:53
0
\$\begingroup\$

In my game I currently have this system in place. Unfortunately it is in c# and you might not be able to get what you are looking for. What I do is store the location of the player, and the location of the mouse click. When the first click to move happens, I have a boolean that is false until the character reaches the clicked location, or he happens to get stuck.

Keep in mind if you have other game objects, you will need to have a path finding method to check if you are attempting to walk into a collidable object, and have logic in place for your character to navigate around said collidable objects.

For an example of this, feel free to reference my 2D RPG thats a work in progress : https://github.com/shroeder/GameRPG/tree/LukesBranch/Game/Game. Look at the GlobalVariables class, and search for the PathFind method. It returns a boolean that tells the game class if the character has reached his destination or not, and also sets what direction he needs to move in order to navigate around a collidable object. From the game class(game1.cs) you search //character movement to see that it evaluates a GlobalVariables.Dir, which is an enum, to see if the method called in GlobalVariables has set the direction in which to move.

\$\endgroup\$
  • \$\begingroup\$ Sure, I hope it helps. \$\endgroup\$ – Shroeder Oct 28 '14 at 14:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.