Turning arms with mouse cursor

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
lazer_viking
Prole
Posts: 5
Joined: Sat Sep 22, 2012 9:51 pm
Location: Belarus, Minsk

Turning arms with mouse cursor

Post by lazer_viking »

Hey there, for first - sorry for my english, I'm from Belarus. For second - I have an idea of a canabalt-like side-scroll game but with some shooter elements in it, so, it will be about a cowboy... aaaaaand that's all for now. How can it be realized, that arms of cowboy turns with mouse cursor (pistols in both hands kinda looking at the mouse cursor in any time)
Image
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Turning arms with mouse cursor

Post by Robin »

Welcome!

How do you want the arms to turn? Completely or just left/right? If you want the first, you can use trigonometry to calculate the angle between your cowboy and the cursor. If the latter, you just have to check which x-coordinate is larger: the cursor's or the cowboy's.

Good luck, and keep asking questions if something's not clear.
Help us help you: attach a .love.
lazer_viking
Prole
Posts: 5
Joined: Sat Sep 22, 2012 9:51 pm
Location: Belarus, Minsk

Re: Turning arms with mouse cursor

Post by lazer_viking »

Thank you!
The axis of rotation in the forearm, hands, ideally, should describe the sector of the circle. Picture realated.
Image
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Turning arms with mouse cursor

Post by Nixola »

Then it's the first of Robin's solutions, with a "cap" to the angle (math.min and math.max, or a simple "if angle >= x then...")
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
lazer_viking
Prole
Posts: 5
Joined: Sat Sep 22, 2012 9:51 pm
Location: Belarus, Minsk

Re: Turning arms with mouse cursor

Post by lazer_viking »

Yeah, thanx, but...umghh, stupid question - how to make arms rotatable, should I use animation lib for it?
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Turning arms with mouse cursor

Post by Robin »

I think -- but I might be wrong -- that what would be easiest would be to make all images of the cowboy without arms and then draw the arms separately.

You could use an animation library, but you don't have to, necessarily.
Help us help you: attach a .love.
lazer_viking
Prole
Posts: 5
Joined: Sat Sep 22, 2012 9:51 pm
Location: Belarus, Minsk

Re: Turning arms with mouse cursor

Post by lazer_viking »

Yep, I thought about this variant too, but I don't know yet, how to make cowboy jump not separately with his hands in this case.
User avatar
paritybit
Citizen
Posts: 53
Joined: Thu Sep 06, 2012 3:52 am

Re: Turning arms with mouse cursor

Post by paritybit »

You'll just want to move the cowboy and his arms at the same time. The simplest way would be to move the cowboy and his arms at the same velocity -- so if the cowboy moves 5 horizontally and 5 vertically, so would his arms and they'd be together. But there are other ways to accomplish this depending on the effect you want. For example, you could keep the cowboy in the center of the screen and move all of the world around him instead of him -- then you don't have to worry about moving them together.

With Love2d, you've got complete control.
lazer_viking
Prole
Posts: 5
Joined: Sat Sep 22, 2012 9:51 pm
Location: Belarus, Minsk

Re: Turning arms with mouse cursor

Post by lazer_viking »

Thanx, I think now I have direction to work in.
User avatar
paritybit
Citizen
Posts: 53
Joined: Thu Sep 06, 2012 3:52 am

Re: Turning arms with mouse cursor

Post by paritybit »

You inspired me to make something for my son who is going through a cowboy phase. A little broken now, but you can see it here.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 49 guests