Trouble With Math.

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
User avatar
Crossing
Prole
Posts: 42
Joined: Sat Mar 21, 2015 3:37 pm

Trouble With Math.

Post 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!
Attachments
test.love
(3.44 KiB) Downloaded 114 times
Manyrio
Prole
Posts: 29
Joined: Sat Feb 06, 2016 10:12 am

Re: Trouble With Math.

Post 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
function love.load() end
function love.update(dt) end
function love.draw() end
emalb
Prole
Posts: 1
Joined: Tue Jul 12, 2016 1:20 pm
Location: London

Re: Trouble With Math.

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

Who is online

Users browsing this forum: Bing [Bot] and 11 guests