How do I make player move to a position clicked on screen

I’m taking my old nostalgic game MU Online and Runescape as reference to my upcoming project, I succssed in making an isometric camera for it in order to take shape, now I wanna disable to usage of WASD as movement but make player move to a certain position click on screen and face that position clicked.

I don’t need a whole script but pinpoints to where I should look in order to achieve that kind of movement mechanic.

Roblox has a default behavior already implemented to do this. Go into StarterPlayer and go to DevComputerMovementMode and DevTouchMovementMode, there you can choose ClickToMove.

By the way, right-click the mouse to move if you use a computer.

1 Like

You’ll want to utilize remote events, to send mouse data from the client to the server.

Once the server gets the mouse click location (use Google, pretty simple way to get it client sided), move the player to that point (using whichever move methods of your choice).

Also, to face a player to a location, you’ll want to utilize CFrame.lookAt method on a players primary part.

This is of the assumption that everything, but the initial mouse position logic is handled server sided.

Edit: or try what the guy above me said lol

1 Like

I was trying that, I see a bit of a delay from the input to the server actually recognizing the character is moving, and there is any way to replace the right click in the mouse to left click and make it more smoothly move? and not in sort of packloss delay?

The delay you are encountering might very well be normal network latency. Any data will take time to travel from the client to the server.

Yeah there’s no way to reduce that, that’s normal latency.

But, you can do all of this client sided which would smooth it out, and just do some interp stuff on the server so the player models are somewhat in sync (across the server, for other players)

There is something you can do about this, but it does involve editing core scripts.

Firstly, copy PlayerModule from StarterPlayerScripts when playtesting the game. After exiting the playtest, paste PlayerModule into StarterPlayerScripts. Under ControlModule, parented under PlayerModule, there is a module script called ClickToMoveController. On line 544, there is a wait function. Set the interval to 0 or remove it entirely. It seemed to have a faster response time when I did that.

Please take the comment in mind though above the wait statement if the character has to jump at some point.

2 Likes

I don’t see where I should involve jump mechanics in this type of genre since both games do not use jumps whatsoever, but… I have seen like in Elder Scrolls Online in order to actually traverse to places they use sort of system that makes the player jump by itself, that’s some I’d consider in my mind.

@MonkeyIncorporated I will test out in the current baseplate if such thing will work, will update.

Ok after doing some testing, it doesn’t appear that it affects anything related to responsiveness. I do have another idea though. Since it uses pathfinding, it likes to create a point where the character is, causing a slight delay in movement. Setting the statement on line 235 to 1 may help.

I tested the same with different timers, still I see no chances in responsiveness, even tho after editing line 235, I see maybe a slight difference but it’s still sorta laggy/rubberbanding the camera/player

If you’ve ever played Conquer Online, i quickly prototyped a jumping system like that, i can share the code (thought it’s a little buggy and I didn’t spend time on smoothing it out). It’s server sided.

Watch jumping | Streamable

I would say the best option then would be to create a new movement system like @elmlingg suggested. My best guess is that the delay is due to path computation, but I can’t be sure.

Also, would you mind sending a video of the delay you are talking about? I don’t seem to have a noticeable delay like the one you claim to have.

Yeah, that’s what I meant that ESO is using aswell to traverse between places, I be happy to have that system if you don’t mind sharing, could be using in some places to jump above blocking tree log etc…

I have found that the delay came from my side as somewhat my ping is hella high and seemingly effects the player actions, I will see if this problem persists in near future but right now its doing okay and exactly what I needed.

@MonkeyIncorporated btw, do you know maybe how to change from the key from RMB to LMB?

In lines 889 through 899 of ClickToMoveController, change any mention of MouseButton2 into MouseButton1, don’t forget to include the mouse up times, down times, etc.

Somewhat it disabled my movement completely. :confused:

I have also seem to encounter a bug where you gotta press few times in order for it to change direction, and it doesn’t do it smooth either, there is a way to smoothen the movement?

This should be what the code looks like for the if statement on line 889:

if input.UserInputType == Enum.UserInputType.MouseButton1 then
	self.mouse1UpTime = tick()
	local currPos: Vector3 = input.Position
	-- We allow click to move during path following or if there is no keyboard movement
	local allowed = ExistingPather or self.keyboardMoveVector.Magnitude <= 0
	if self.mouse1UpTime - self.mouse1DownTime < 0.25 and (currPos - self.mouse1DownPos).magnitude < 5 and allowed then
		local positions = {currPos}
		OnTap(positions)
	end
end

Also, I’m not encountering the bug you mentioned. If the bug persists after putting this code in, delete the PlayerModule and copy it again using the method I mentioned. Then replace the if statement with the code above.