I am currently having a blank moment, I'm trying to get an image, lets say the image is a cube and its in the middle of the screen, how would i go about making one face of the cube angle towards the cursor and rotate the cube to where the cursor is.
No need to write out a whole script, just say a good way of going about doing it, thanks.
Rotation of image pointing towards mouse?
Re: Rotation of image pointing towards mouse?
Woo, thanks.
That's basically what i have done to get it working for now..
Code: Select all
playerR = math.atan2(mouseY-playerY, mouseX-playerX)
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: Rotation of image pointing towards mouse?
I usually wrap that into a function like this:
It makes things easier to remember.
Code: Select all
function math.angle(x1, y1, x2, y2)
return math.atan2(y2 - y1, x2 - x1)
end
Re: Rotation of image pointing towards mouse?
Yeah, also makes the code much cleaner.BlackBulletIV wrote:I usually wrap that into a functions,
It makes things easier to remember.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Rotation of image pointing towards mouse?
I would suggest not putting it in the math library, as that library is standard but that function is not. People reading your code would expect math.* to be one of the standard library functions.
Help us help you: attach a .love.
- Jasoco
- Inner party member
- Posts: 3727
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Rotation of image pointing towards mouse?
I just name my function getAngle(). Or distanceFrom() for distance.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: Rotation of image pointing towards mouse?
Each to their own I guess, but I find it nicer looking to put it in with the math library. It wouldn't take long for someone to figure out it's not part of the math library anyway.Robin wrote:I would suggest not putting it in the math library, as that library is standard but that function is not. People reading your code would expect math.* to be one of the standard library functions.
Re: Rotation of image pointing towards mouse?
Unless you want them to be confusedRobin wrote:People reading your code would expect math.* to be one of the standard library functions.
Who is online
Users browsing this forum: Ahrefs [Bot] and 4 guests