Page 1 of 1

Trouble With Math.

Posted: Tue Jul 12, 2016 9:34 am
by Crossing
Hey guys.
So I decided to make my RPG point and click, however I've already encountered a problem haha.

I got the basics down but for some reason I'm having truoble with the landing and it seems pretty glitchy on the ride.

Basically from point A (where my player image is residing) to point B (the point inwhich mouse is clicked) the first thing the image does it rotate. Perfect. Then it moves to the point clicked. At this point maybe it is just me but it seems buggy while moving. Then once it gets to the end it makes a double image. I'm assuming that's because the code is telling it if it's not at the correct point (Which i know it will never be) to keep trying to get there. How do i stop this? Also how can I get around having to not call MouseX, MouseY in love.load.

Love file below.

Thanks!

Re: Trouble With Math.

Posted: Tue Jul 12, 2016 10:36 am
by Manyrio
I didn't check the code but I thin it is because the player don't stop moving. So to stop that you can do something like :

Code: Select all

if player.x == pointB.x and player.y == pointB.y then
	-- create a function that stop the player, for the exemple I will use :
	player.stopMoving()
end

Re: Trouble With Math.

Posted: Tue Jul 12, 2016 1:24 pm
by emalb
What I tend to do is track the distance to my destination. So when you click, calculate the distance and store it. With each update, calculate your current distance to the destination. If it's got bigger than it was on the last update then you've either reached or overshot your destination, so set your current position to your destination position and stop moving.

Don't forget that after you've checked the distance to the destination, you'll need to store that distance, so you know what to compare it to next time.