Mouse sensitivity [SOLVED]

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.
User avatar
Chroteus
Citizen
Posts: 89
Joined: Wed Mar 20, 2013 7:30 pm

Mouse sensitivity [SOLVED]

Post by Chroteus »

Considering love2d has no love.mouse.setSensitivity() function, can I somehow change the sensitivity using love.mouse.set[X,Y]() functions?
Last edited by Chroteus on Tue Feb 11, 2014 12:46 pm, edited 1 time in total.
User avatar
Chroteus
Citizen
Posts: 89
Joined: Wed Mar 20, 2013 7:30 pm

Re: Mouse sensitivity

Post by Chroteus »

To illustrate my point better, I'll upload the love file. My goal is to decrease sensitivity as you zoom-in.
Attachments
clay.love
(7.32 MiB) Downloaded 176 times
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Mouse sensitivity

Post by Plu »

It should be possible to control the mouse speed using set functions, yes.

You have to remember the previous location, and then calculate how far the mouse would have moved and divide those by some amount to slow the mouse down.

Code: Select all

love.load()
  oldX, oldY = love.mouse.getPosition()
  slow = 2 -- half as fast
end

love.update( dt )
  x, y = love.mouse.getPosition()
  xDiff = ( oldX - x ) / slow
  yDiff = ( oldY - y ) / slow
  love.mouse.setPosition( oldX + xDiff, oldY + yDiff )
  oldX, oldY = love.mouse.getPosition()
end
Something like above should work, I think.
EDITED: Shouldn't use abs; speed can be negative.
Last edited by Plu on Mon Feb 10, 2014 2:34 pm, edited 1 time in total.
Zarty55
Citizen
Posts: 79
Joined: Thu Jul 25, 2013 2:36 am

Re: Mouse sensitivity

Post by Zarty55 »

I got it to be faster, but it's harder than I thought to make it slower haha

I have this:

Code: Select all

function love.load(arg)
  oldMouseX, oldMouseY = love.mouse.getPosition()
  sensitivity = 5 -- 20% faster
end

function love.draw()
  local newMouseX, newMouseY = love.mouse.getPosition()
  dX, dY = ((newMouseX - oldMouseX)*sensitivity), ((newMouseY - oldMouseY)*sensitivity)
  
  oldMouseX, oldMouseY = newMouseX + dX, newMouseY + dY
  love.mouse.setPosition(oldMouseX, oldMouseY)
end
But it won't slow down too much for some reason...

Edit: It's really bugged btw.

Also, I'm not sure if it fits that well in love.draw, I put it there cause it seemed to be better.
Last edited by Zarty55 on Mon Feb 10, 2014 2:20 pm, edited 2 times in total.
User avatar
Daniel Eakins
Citizen
Posts: 99
Joined: Thu Jul 18, 2013 9:14 pm
Location: France

Re: Mouse sensitivity

Post by Daniel Eakins »

You can maybe slow it by limiting FPS (only for your mouse movement function, not all of the game obviously).

http://love2d.org/forums/viewtopic.php?p=57977#p57977
User avatar
Chroteus
Citizen
Posts: 89
Joined: Wed Mar 20, 2013 7:30 pm

Re: Mouse sensitivity

Post by Chroteus »

Thanks for your contributions, but the mouse either was "slipping away" or was just stuck to my screen's right edge. Daniel, the mouse didn't slow down but just became choppy. After all, that's the point of delta time. To make entities move independent of framerate. Anyway, you guys gave me some ideas, and I'll try to come up with something of my own.

EDIT: Still, I'm open for suggestions.
Last edited by Chroteus on Mon Feb 10, 2014 2:34 pm, edited 1 time in total.
User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: Mouse sensitivity

Post by Plu »

@Zarty: you are modifying the mouse by adding to the new coordinates, this is causing it to act weird. You have to discard the new coordinates and work from the old coordinates again if you're determining the position difference manually. Otherwise you're adding both the normal mouse speed and your recalculated one.

Also I spotted a bug in my own which I'm fixing now.
User avatar
Chroteus
Citizen
Posts: 89
Joined: Wed Mar 20, 2013 7:30 pm

Re: Mouse sensitivity

Post by Chroteus »

Anyway, I decided to make my game fullscreen. Although, I still can't set the sensitivity of mouse, it's no longer a problem now.
User avatar
Azhukar
Party member
Posts: 478
Joined: Fri Oct 26, 2012 11:54 am

Re: Mouse sensitivity

Post by Azhukar »

This is not a problem of sensitivity but the way you trace mouse coordinates to tile coordinates. You need to transform your mouse coordinates to correspond with your drawing transformations.
User avatar
Chroteus
Citizen
Posts: 89
Joined: Wed Mar 20, 2013 7:30 pm

Re: Mouse sensitivity

Post by Chroteus »

Azhukar wrote:This is not a problem of sensitivity but the way you trace mouse coordinates to tile coordinates. You need to transform your mouse coordinates to correspond with your drawing transformations.
While I was aware that mouse's real position and the way it is interpereted wasn't the same, I thought I had a bug somewhere and was trying to fix it for hours. Later, I read your post again and you gave me an idea to read the camera lib's documentation more carefully. And... there was a nifty function called worldCoords which converted the mouse coordinates. Alright, I'll mark it as solved, even though there isn't a proper way to set the mouse sensitivity yet.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Google [Bot] and 31 guests