Mouse controlled player movement; help please

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply

Is the game idea even any good anyway?

Yeah, it sounds great!
3
60%
maybe, it could be fun
2
40%
No, It makes me sad just thinking about it!
0
No votes
 
Total votes: 5

User avatar
xXweeguyXx
Prole
Posts: 5
Joined: Fri Aug 16, 2013 9:57 pm

Mouse controlled player movement; help please

Post 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
Attachments
Game_Test.love
Here's the .love!
(2.78 KiB) Downloaded 195 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Mouse controlled player movement; help please

Post by Robin »

Welcome! What exactly is your question?
Help us help you: attach a .love.
User avatar
Rhinoceros
Prole
Posts: 35
Joined: Mon Jun 11, 2012 2:59 am
Location: Under the Floorboards

Re: Mouse controlled player movement; help please

Post by Rhinoceros »

I'm pretty sure that they want the character to move to where the mouse was clicked, as per standard RTS style.
User avatar
xXweeguyXx
Prole
Posts: 5
Joined: Fri Aug 16, 2013 9:57 pm

Re: Mouse controlled player movement; help please

Post 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:
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Mouse controlled player movement; help please

Post 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.
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Re: Mouse controlled player movement; help please

Post 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.
"In those quiet moments, you come into my mind" - Liam Reilly
User avatar
xXweeguyXx
Prole
Posts: 5
Joined: Fri Aug 16, 2013 9:57 pm

Re: Mouse controlled player movement; help please

Post 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
User avatar
xXweeguyXx
Prole
Posts: 5
Joined: Fri Aug 16, 2013 9:57 pm

Re: Mouse controlled player movement; help please

Post 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!
User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Re: Mouse controlled player movement; help please

Post 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).
"In those quiet moments, you come into my mind" - Liam Reilly
User avatar
xXweeguyXx
Prole
Posts: 5
Joined: Fri Aug 16, 2013 9:57 pm

Re: Mouse controlled player movement; help please

Post 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
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 2 guests