mouse direction
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- IAsep-TrixI
- Citizen
- Posts: 89
- Joined: Mon Aug 12, 2013 4:22 am
- Location: Philippines,Asia
mouse direction
I was just wondering, how to check the mouse direction, because for my new game that Im working on in my spare time, he will look left and right when either A or D is pressed, but what I want him to do is that when my mouse is on the left or right from the middle of the screen and I click, it will face the direction of the mouse (not rotate just normal left and right direction)
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: mouse direction
Code: Select all
if mouse.x < screen.width / 2 then
-- mouse is on the left half of the screen
else
-- mouse is on the right half of the screen
end
- IAsep-TrixI
- Citizen
- Posts: 89
- Joined: Mon Aug 12, 2013 4:22 am
- Location: Philippines,Asia
Re: mouse direction
I only want it to update when the mouse is clicked, should I do something likeDaedalusYoung wrote:Code: Select all
if mouse.x < screen.width / 2 then
If mouse is clicked then
if mouse.x < screen.width/2 then
blah blahb lah
end
end
?
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
- IAsep-TrixI
- Citizen
- Posts: 89
- Joined: Mon Aug 12, 2013 4:22 am
- Location: Philippines,Asia
Re: mouse direction
It worked! It kinda didnt work right, so I tweaked it a bit to my likings so instead of screenWidth it is not player.x so that it goes left/right according to the players locationDaedalusYoung wrote:Code: Select all
if mouse.x < screen.width / 2 then -- mouse is on the left half of the screen else -- mouse is on the right half of the screen end
Thanks for the help guys!
- IAsep-TrixI
- Citizen
- Posts: 89
- Joined: Mon Aug 12, 2013 4:22 am
- Location: Philippines,Asia
Re: mouse direction
It worked at first but when I started using tiled and the camera lib it started to mess up, do you know whats causing this?DaedalusYoung wrote:Code: Select all
if mouse.x < screen.width / 2 then -- mouse is on the left half of the screen else -- mouse is on the right half of the screen end
- DaedalusYoung
- Party member
- Posts: 413
- Joined: Sun Jul 14, 2013 8:04 pm
Re: mouse direction
I've never used any libs, so I can only guess. The camera lib might change the mouse position value based on scale/translation/rotation.
Re: mouse direction
Most likely the mouse is using screen coördinates, while the player is using world coördinates. There is most likely a function to convert between the two in the library; make sure both are using the same coördinate system.
- IAsep-TrixI
- Citizen
- Posts: 89
- Joined: Mon Aug 12, 2013 4:22 am
- Location: Philippines,Asia
Re: mouse direction
I was doingPlu wrote:Most likely the mouse is using screen coördinates, while the player is using world coördinates.
Code: Select all
if mouse.x > player.x then
blah blah blah
end
Who is online
Users browsing this forum: Amazon [Bot], Bing [Bot] and 4 guests