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.

Post by zac199 »

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.
User avatar
mike
Administrator
Posts: 364
Joined: Mon Feb 04, 2008 5:24 pm

Re: Rotating image to follow mouse.

Post by mike »

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.

Post by zac199 »

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.
User avatar
mikembley
Citizen
Posts: 72
Joined: Wed Dec 17, 2008 5:30 pm
Location: Blackburn, UK
Contact:

Re: Rotating image to follow mouse.

Post by mikembley »

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
(16.12 KiB) Downloaded 384 times
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Rotating image to follow mouse.

Post by bartbes »

@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.

Post by zac199 »

Haha that is a pretty nifty example, and yes thats exactly what I want to do :P. But mind telling me how to look at the script haha
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Rotating image to follow mouse.

Post by bartbes »

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.

Post by zac199 »

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() )
User avatar
mikembley
Citizen
Posts: 72
Joined: Wed Dec 17, 2008 5:30 pm
Location: Blackburn, UK
Contact:

Re: Rotating image to follow mouse.

Post by mikembley »

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.

Post by zac199 »

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 :P
Post Reply

Who is online

Users browsing this forum: No registered users and 57 guests