Page 1 of 1

Turning arms with mouse cursor

Posted: Sun Sep 23, 2012 6:26 am
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

Re: Turning arms with mouse cursor

Posted: Sun Sep 23, 2012 12:11 pm
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.

Re: Turning arms with mouse cursor

Posted: Sun Sep 23, 2012 1:38 pm
by lazer_viking
Thank you!
The axis of rotation in the forearm, hands, ideally, should describe the sector of the circle. Picture realated.
Image

Re: Turning arms with mouse cursor

Posted: Sun Sep 23, 2012 1:56 pm
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...")

Re: Turning arms with mouse cursor

Posted: Sun Sep 23, 2012 2:13 pm
by lazer_viking
Yeah, thanx, but...umghh, stupid question - how to make arms rotatable, should I use animation lib for it?

Re: Turning arms with mouse cursor

Posted: Sun Sep 23, 2012 2:53 pm
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.

Re: Turning arms with mouse cursor

Posted: Sun Sep 23, 2012 4:21 pm
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.

Re: Turning arms with mouse cursor

Posted: Sun Sep 23, 2012 4:30 pm
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.

Re: Turning arms with mouse cursor

Posted: Sun Sep 23, 2012 4:42 pm
by lazer_viking
Thanx, I think now I have direction to work in.

Re: Turning arms with mouse cursor

Posted: Tue Sep 25, 2012 8:13 am
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.