How to make an object rotate towards the mouse position.
Posted: Wed Feb 17, 2021 9:22 pm
Summary:
Essentially, I've looked up several different ways to look this up and I get the gist of what's going on with the math.atan2 and various other ways of getting the angle to face towards the mouse position. Though; I'm still having a bit of trouble with trying to get the object to face completely towards the mouse and not spin all over the place like it's currently doing right now.
Problem:
The object that I'm trying to get to rotate towards the mouse position spins around rapidly whenever I move the mouse (even a miniscule amount makes it spin out of control.) As you can see in the gif here, I'm using degrees instead of radians with the math.deg() method, however; even that doesn't prevent the spinning for some reason.
Attempted Fixes:
TowerDefense Files
Essentially, I've looked up several different ways to look this up and I get the gist of what's going on with the math.atan2 and various other ways of getting the angle to face towards the mouse position. Though; I'm still having a bit of trouble with trying to get the object to face completely towards the mouse and not spin all over the place like it's currently doing right now.
Problem:
The object that I'm trying to get to rotate towards the mouse position spins around rapidly whenever I move the mouse (even a miniscule amount makes it spin out of control.) As you can see in the gif here, I'm using degrees instead of radians with the math.deg() method, however; even that doesn't prevent the spinning for some reason.
Attempted Fixes:
- Reversing math.atan2 parameters
- Attempted to make the first parameter of math.atan2 negative. - ohai
Code: Select all
local y = -(self.y -(love.mouse.getY()/5))
TowerDefense Files