Page 1 of 1

Mouse controlled player movement; help please

Posted: Sat Aug 17, 2013 5:39 pm
by xXweeguyXx
Hai,
As I'm sure you can tell I'm a newcomer to this site, to the language lua, and to this tremendous game engine LÖVE2D.
I had the idea to make a top down 2d fighting game using traditional M.O.B.A controls ("q" "w" "e" "r" for each individual ability/attack and mouse clicks to control where the player moves) Now, unfortunately due to my lack of lua knowledge and general idiocy I couldn't figure out how to change my currently
"w" "a" "s" "d" controlled character to mouse click control. I am aware this has been answered to before but after reading through the answer many times yet still failing to fully understand it I decided to ask the forums again despite it voiding the forum rules.
thank you very much for your time!
you are all awesome! :ultrahappy:
~Weeguy

Re: Mouse controlled player movement; help please

Posted: Sat Aug 17, 2013 7:02 pm
by Robin
Welcome! What exactly is your question?

Re: Mouse controlled player movement; help please

Posted: Sat Aug 17, 2013 7:06 pm
by Rhinoceros
I'm pretty sure that they want the character to move to where the mouse was clicked, as per standard RTS style.

Re: Mouse controlled player movement; help please

Posted: Sat Aug 17, 2013 8:37 pm
by xXweeguyXx
Robin wrote:Welcome! What exactly is your question?
Thankyou kind sir!
I'm sorry for not making clear, my question was how would I go about making mouse controlled player, as Rhinoceros said "as per standard RTS style" :ultraglee:

Re: Mouse controlled player movement; help please

Posted: Sat Aug 17, 2013 9:32 pm
by Jasoco
You'll need to get a pathfinding library first, preferably one with coroutines. (So the game doesn't halt when each character is checking for a path) If your game is standard tile based it'll be easy-ish. You'll need to make sure the pathfinding algorithm is aware of your map format. i.e. how each grid space is marked as solid or not.

Then when you click, you figure out which tile was clicked, tell the currently commanding characters to calculate a path to that tile. Then follow that path block by block one step at a time.

Complicated? Eh, maybe. I dunno.

Re: Mouse controlled player movement; help please

Posted: Sat Aug 17, 2013 9:51 pm
by Eamonn
I'm not exactly sure how to do it, but in theroy:

You'd have a player's destinationX and destinationY value. Where ever the mouse clicks, make that the destinationX and destinationY value. If the player is not at that position yet, make the player move towards that position. I have tried to do this with your code, but for some reason it isn't working. There's the logic behind it: Make a desX and desY variable. Make it where ever the user clicks. Check if the player's X and Y position are not there yet and move them. Example:

Code: Select all

	if player.x < desX then
  		player.x = player.x - player.speed * dt
	end

	if player.x > desX then
  		player.x = player.x + player.speed * dt
	end

	if player.y < desY then
  		player.y = player.y - player.speed * dt
	end

	if player.y > desY then
  		player.y = player.y + player.speed * dt
	end
Welcome to the LÖVEly world of LÖVE. We hope you enjoy your stay :D I see we have another sockmunkeedev tutorial video watcher... yeah, I can tell by your code. He does awesome tutorials.

EDIT: Guess VeeThree beat me to it! It's basically just pathfinding though. Check out Jumper if you want to use a library. If not, figure things out and learn.

Re: Mouse controlled player movement; help please

Posted: Sat Aug 17, 2013 10:01 pm
by xXweeguyXx
Jasoco wrote:You'll need to get a pathfinding library first, preferably one with coroutines. (So the game doesn't halt when each character is checking for a path) If your game is standard tile based it'll be easy-ish. You'll need to make sure the pathfinding algorithm is aware of your map format. i.e. how each grid space is marked as solid or not.

Then when you click, you figure out which tile was clicked, tell the currently commanding characters to calculate a path to that tile. Then follow that path block by block one step at a time.

Complicated? Eh, maybe. I dunno.
Thankyou very much :) It seems a little complex but i'll try

Re: Mouse controlled player movement; help please

Posted: Sat Aug 17, 2013 10:03 pm
by xXweeguyXx
Eamonn wrote:I'm not exactly sure how to do it, but in theroy:

You'd have a player's destinationX and destinationY value. Where ever the mouse clicks, make that the destinationX and destinationY value. If the player is not at that position yet, make the player move towards that position. I have tried to do this with your code, but for some reason it isn't working. There's the logic behind it: Make a desX and desY variable. Make it where ever the user clicks. Check if the player's X and Y position are not there yet and move them. Example:

Code: Select all

	if player.x < desX then
  		player.x = player.x - player.speed * dt
	end

	if player.x > desX then
  		player.x = player.x + player.speed * dt
	end

	if player.y < desY then
  		player.y = player.y - player.speed * dt
	end

	if player.y > desY then
  		player.y = player.y + player.speed * dt
	end
Welcome to the LÖVEly world of LÖVE. We hope you enjoy your stay :D I see we have another sockmunkeedev tutorial video watcher... yeah, I can tell by your code. He does awesome tutorials.

EDIT: Guess VeeThree beat me to it! It's basically just pathfinding though. Check out Jumper if you want to use a library. If not, figure things out and learn.
Again many thanks!
Yeah sorry about that... "see we have another sockmunkeedev tutorial video watcher" but hey you've got to start some where!

Re: Mouse controlled player movement; help please

Posted: Sat Aug 17, 2013 10:31 pm
by Eamonn
xXweeguyXx wrote:
Eamonn wrote:I'm not exactly sure how to do it, but in theroy:

You'd have a player's destinationX and destinationY value. Where ever the mouse clicks, make that the destinationX and destinationY value. If the player is not at that position yet, make the player move towards that position. I have tried to do this with your code, but for some reason it isn't working. There's the logic behind it: Make a desX and desY variable. Make it where ever the user clicks. Check if the player's X and Y position are not there yet and move them. Example:

Code: Select all

	if player.x < desX then
  		player.x = player.x - player.speed * dt
	end

	if player.x > desX then
  		player.x = player.x + player.speed * dt
	end

	if player.y < desY then
  		player.y = player.y - player.speed * dt
	end

	if player.y > desY then
  		player.y = player.y + player.speed * dt
	end
Welcome to the LÖVEly world of LÖVE. We hope you enjoy your stay :D I see we have another sockmunkeedev tutorial video watcher... yeah, I can tell by your code. He does awesome tutorials.

EDIT: Guess VeeThree beat me to it! It's basically just pathfinding though. Check out Jumper if you want to use a library. If not, figure things out and learn.
Again many thanks!
Yeah sorry about that... "see we have another sockmunkeedev tutorial video watcher" but hey you've got to start some where!
No, I meant it was good that you started with him. He has awesome tutorials. What I meant was: Don't copy his tutorials almost line for line. It's almost exactly like copy and pasting. Maybe try changing a few things up e.g. adding another menu or something? Just avoid copy and paste where possible. I'm sure a lot of people can agree. Sorry if I came across a bit bossy or mean or anything :| I just like to see who people start LÖVE with. I started with Sock, but I know some people started with NeoSilky by their code and I also know some people that started with Goature because of their code. I've watched all the tutorials listed on the wiki and read through the wiki tutorials many times. I started with Sock, but I did change a lot of things from his tutorials.

Also, you might want to not double post. If you were like me and haven't been on many forums, you may not know what double posting is. Basically, it's when you post 2 threads in a row without letting another person post inbetween. Maybe merged your 2 posts together? You won't get banned for doing it, but you might just get told off or something.

As for the games idea, it sounds fun, but I don't know if it will be purely because we only know that the ball can move from where the mouse is clicked. That sounds very VERY awesome(I tried doing that, didn't work, and just didn't do it).

Re: Mouse controlled player movement; help please

Posted: Sat Aug 17, 2013 11:42 pm
by xXweeguyXx
Eamonn wrote:
xXweeguyXx wrote:
Eamonn wrote:I'm not exactly sure how to do it, but in theroy:

You'd have a player's destinationX and destinationY value. Where ever the mouse clicks, make that the destinationX and destinationY value. If the player is not at that position yet, make the player move towards that position. I have tried to do this with your code, but for some reason it isn't working. There's the logic behind it: Make a desX and desY variable. Make it where ever the user clicks. Check if the player's X and Y position are not there yet and move them. Example:

Code: Select all

	if player.x < desX then
  		player.x = player.x - player.speed * dt
	end

	if player.x > desX then
  		player.x = player.x + player.speed * dt
	end

	if player.y < desY then
  		player.y = player.y - player.speed * dt
	end

	if player.y > desY then
  		player.y = player.y + player.speed * dt
	end
Welcome to the LÖVEly world of LÖVE. We hope you enjoy your stay :D I see we have another sockmunkeedev tutorial video watcher... yeah, I can tell by your code. He does awesome tutorials.

EDIT: Guess VeeThree beat me to it! It's basically just pathfinding though. Check out Jumper if you want to use a library. If not, figure things out and learn.
Again many thanks!
Yeah sorry about that... "see we have another sockmunkeedev tutorial video watcher" but hey you've got to start some where!
No, I meant it was good that you started with him. He has awesome tutorials. What I meant was: Don't copy his tutorials almost line for line. It's almost exactly like copy and pasting. Maybe try changing a few things up e.g. adding another menu or something? Just avoid copy and paste where possible. I'm sure a lot of people can agree. Sorry if I came across a bit bossy or mean or anything :| I just like to see who people start LÖVE with. I started with Sock, but I know some people started with NeoSilky by their code and I also know some people that started with Goature because of their code. I've watched all the tutorials listed on the wiki and read through the wiki tutorials many times. I started with Sock, but I did change a lot of things from his tutorials.

Also, you might want to not double post. If you were like me and haven't been on many forums, you may not know what double posting is. Basically, it's when you post 2 threads in a row without letting another person post inbetween. Maybe merged your 2 posts together? You won't get banned for doing it, but you might just get told off or something.

As for the games idea, it sounds fun, but I don't know if it will be purely because we only know that the ball can move from where the mouse is clicked. That sounds very VERY awesome(I tried doing that, didn't work, and just didn't do it).
I didn't take it as you being bossy :P I just thought seeing people requesting for help that have basically the exact same lines of code might get a bit monotonous... any who I've decided to stick to making a simpler game :P Using only trial and error and the wiki! :crazy: I'll keep the idea for this fighting game just in case i ever get good at lua and think i can do it.
Thankyou again for all your advice, you're a great guy :D maybe i'll see you again on the forums but maybe next time not because i'm requesting help :P