Java-Gaming.org Hi !
 Featured games (91) games approved by the League of Dukes Games in Showcase (799) Games in Android Showcase (237) games submitted by our members Games in WIP (865) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: 1 [2]
 ignore  |  Print
 How to code a sword swipe?  (Read 25545 times) 0 Members and 1 Guest are viewing this topic.
Zeldar
 « Reply #30 - Posted 2015-08-17 11:48:54 »

Yes that might work ! but does it works for all the cases?

For example if I want the first (outer) rotation to be far from the sword like O.x = x - 500 and O.y = y
And the second (inner) rotation to, not be in the middle of the sword, but at it's grip, something like O2.x = x + 40 and O2.y = y + 20

Should I do something like
 1  2 O2.x = (xNew + O.x) / 2.0 + 40O2.y = (yNew + O.y) / 2.0 + 20

to place it where I want ?

edit: the code in this message is false

KaiHH

JGO Kernel

Medals: 764

 « Reply #31 - Posted 2015-08-17 11:55:46 »

Yes that might work ! but does it works for all the cases?
Depends on what you mean by all cases.
I mean, the formula makes an assumption that the center of rotation for the second rotation is always halfway between O and 'B', because that was how it looked like in your image. If you were to rotate a point 'A' that is not the tip of the sword, then of course also the second rotation center will be different.
And if you choose anoter rotation center for the first/outer rotation, then also everything will be different.
The formula (A + B) / 2 is just used to find the center between A and B.
You can of course compute O2 however you like and make it depend on any other computed value or constant.
Zeldar
 « Reply #32 - Posted 2015-08-17 12:19:15 »

Ok I got it I modified the formula a bit to place the other centre points where I want
Zeldar
 « Reply #33 - Posted 2015-08-17 12:56:52 »

Alright that's it! I can now translate, do multiple rotations with multitple centre points and everything works wonderfully!
Look at how amazing it looks even without any textures, these are just the polygons but it's so cool already

Big thanks to everybody for the help !
KaiHH

JGO Kernel

Medals: 764

 « Reply #34 - Posted 2015-08-17 13:06:10 »

Looks really nice! At some points it even looks like it's somehow 3D-ish.
CelestialCreator
 « Reply #35 - Posted 2015-08-17 13:57:30 »

Looks amazing! Does it work if you rotate the sword in the other direction?
Zeldar
 « Reply #36 - Posted 2015-08-17 14:38:01 »

Looks amazing! Does it work if you rotate the sword in the other direction?

I'm trying to implement this into my game to show every posibilities when it will be ready
CelestialCreator
 « Reply #37 - Posted 2015-08-17 15:00:22 »

I'm trying to implement this into my game to show every posibilities when it will be ready

Sounds spiffy. Can't wait to play the finished game!
Zeldar
 « Reply #38 - Posted 2015-08-17 17:59:49 »

And here is the swipe system implemented to my game ! Note that it is always active for the show and to make sure that it works for every movements, but in the real game it will be activated only when you are attacking