## Rotating image to follow mouse.

General discussion about LÖVE, Lua, game development, puns, and unicorns.
zac199
Prole
Posts: 5
Joined: Mon Apr 06, 2009 2:02 pm

### Rotating image to follow mouse.

Hi

I was wondering how I could get my image to follow my mouse.

Like have the front of the image always looking at the mouse on the screen.

Just a quick question thanks ahead of time.

mike
Posts: 364
Joined: Mon Feb 04, 2008 5:24 pm

### Re: Rotating image to follow mouse.

You mean that you want a fixed image to rotate to always be "pointing" at the mouse?
Now posting IN STEREO (where available)

zac199
Prole
Posts: 5
Joined: Mon Apr 06, 2009 2:02 pm

### Re: Rotating image to follow mouse.

Sort of... I have a image that moves with W,A,S,D, and I want the... err front so to say to always look at the mouse.

If you dont know what i mean, Im making a top down shooter, and I need to be able to aim haha.

mikembley
Citizen
Posts: 72
Joined: Wed Dec 17, 2008 5:30 pm
Location: Blackburn, UK
Contact:

### Re: Rotating image to follow mouse.

I guess you mean like a top down shooter huh?

I was gonna throw my functions your way and let you figure it out, But im feeling kind today so i made you a demo instead

Have fun

-Forgot to mention: Controls are Arrow keys to move character and mouse click for flamethrower and i apologise for using a jpg, as i stole the image from Google images
Attachments
topdown.love

bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

### Re: Rotating image to follow mouse.

@mikembley: Nice example, though there are some things that could be done better (game-wise, but you're not making a game anyway).

zac199
Prole
Posts: 5
Joined: Mon Apr 06, 2009 2:02 pm

### Re: Rotating image to follow mouse.

Haha that is a pretty nifty example, and yes thats exactly what I want to do . But mind telling me how to look at the script haha

bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

### Re: Rotating image to follow mouse.

A .love is a renamed zip, so you can just open it with your zip program, or you can rename it and then open it.

zac199
Prole
Posts: 5
Joined: Mon Apr 06, 2009 2:02 pm

### Re: Rotating image to follow mouse.

Ah yes. Thanks haha. Now I just need to find were the code is that rotates the img.

EDIT:
would this be it

Code: Select all

player.direction = point_direction( player.x, player.y, love.mouse.getX(), love.mouse.getY() )

mikembley
Citizen
Posts: 72
Joined: Wed Dec 17, 2008 5:30 pm
Location: Blackburn, UK
Contact:

### Re: Rotating image to follow mouse.

That indeed would be it. point_direction is a function that returns the angle between two points

zac199
Prole
Posts: 5
Joined: Mon Apr 06, 2009 2:02 pm

### Re: Rotating image to follow mouse.

So would I use this same method to make the guy shoot? haha. Like I want a actual bullet that travels in a fixed direction, not your flamethrower example

### Who is online

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