How can I implement character movement using the mouse?

Hi, I am new to unreal and am trying to implement some simple MOBA mechanics like from League of Legends for example. I’m trying to use mostly C++ to improve my skill with it since I’ll be trying to get a job in the next year or so.

I want to be able to move my character pawn with the mouse to a location on the map with pathfinding so he doesn’t run into random things on the map. I’m not quite sure how to go about it at all, and I can’t find any examples of people doing the same thing, except with blueprints and the SimpleMoveToPath node thing.

Right now I am able to capture where on the screen I clicked and draw an arrow from my current location to where the click hit something and start walking in that direction using the click vector - location vector and normalizing. And then in Tick I call MovementComponent->Velocity += (velocity) * something. I don’t think this is the best way of doing things however because I’m going to have to implement all of the pathfinding features myself which I figure have already been written.

Anyone done something like this where you can move the character by clicking on the screen? Do I need to change my CharacterController to an AIController? Just at a loss right now.

Hi Sealpuncher,

Have you taken a look at how this is set up in the Top-Down Template project? It should be close to what you are trying to achieve.

Yeah it seems like that has what I need with the MoveToLocation function in AIController. The only problem is right now I have the guy I want to move set up as my main character pawn with a PlayerController. Should I make my character just be an invisible pawn and have it own a separate AIController where I can call MoveToLocation and MoveToActor based on mouse input in my PlayerController class? That seems like a pretty good way to solve the issue except for needing two controllers.

Hi Sealpuncher,

It generally isn’t a very good idea to have more than one controller controlling a single object. What you would probably want to do instead is to create a custom controller that derives from the top down template controller to handle your movement, then add in any custom functionality that you want.

Yeah I finally figured out that it wasn’t even the controller that controls the movement input to the character it’s the character itself. So I can have my movement code in a character with an AIController and control him that way, with my default player pawn just being an invisible mesh with camera controls. Thanks for your help.

Can you please give more details how to fix it? … here is my blueprint…

I simply spawned character and now I like to move (I mean move-animation) it to new location on each tick. My location value is comes up via Tick event and I compare that with “Buffer01” which is previous value… . That`s why there is a branch node here…