Jump to content


Photo

Swinging a First-Person Sword


  • Please log in to reply
5 replies to this topic

#1 8-BitTonberry

8-BitTonberry

    GMC Member

  • GMC Member
  • 557 posts
  • Version:GM8.1

Posted 26 February 2012 - 11:29 PM

Hey, guys! I've made a habit of posting here lately. Hah

So, as I'm plugging away at my game here, I've run into another snag. I'm not so great at transforming models. I can do basic stuff like simple positioning, or opening/closing a door or drawer, but when it comes to actual fluid natural movement, I'm a little stumped.

If anyone could give me a tip, some method that would make moving models a little easier than, say, setting the position for every frame of the animations I'd like, that would be wonderful. =]

This bit seems tricky.

Thanks a lot!

Screenshot for reference:
Posted Image
  • 0

#2 hit172

hit172

    GMC Member

  • New Member
  • 189 posts
  • Version:GM8

Posted 27 February 2012 - 03:32 AM

If the hilt of your sword is positioned at the origin then you could simply rotate it on the x/y axis (the one along the sword edge) to achieve a simple swinging effect.  Just have a swing rotation variable that you increase until it is at 90 degrees or so and then have it decrease back to zero.  You could also use a timeline to move the model every step (not just rotation but transformation also) which could also become a full blown animation system which would come in handy later in the dev process (for enemies and other AI).

Edited by hit172, 27 February 2012 - 03:33 AM.

  • 0

#3 8-BitTonberry

8-BitTonberry

    GMC Member

  • GMC Member
  • 557 posts
  • Version:GM8.1

Posted 27 February 2012 - 01:13 PM

I s'pose it would come in handy. It would just be extremely difficult to work with is all. Hah
  • 0

#4 PivotGamer84

PivotGamer84

    GMC Member

  • New Member
  • 170 posts

Posted 05 March 2012 - 03:13 AM

I s'pose it would come in handy. It would just be extremely difficult to work with is all. Hah


Might I add that the screenshot you have reminds me of Minecraft. Is that the kind of game you are trying to design?
  • 0

#5 allong

allong

    GMC Member

  • GMC Member
  • 191 posts

Posted 12 March 2012 - 02:45 PM

The best method I can think of would be the use of circular functions, such as Sine or Cosine. It provides for smoothness in the swing (as opposed to a fixed speed down and then up)

You can implement it by setting the angle of the sword equal to the result of a sine function, multiplied by the angle you want to swing at, consider:
Posted Image
The y value shown by the curve between 0 and pi is what you want to apply to your angle. (Any further than pi and you will smack yourself in the face)

Here is a shoddy chuck together of an example demonstrating this: Sword Swingery

I hope it is helpful and easy to comprehend ><
  • 0

#6 8-BitTonberry

8-BitTonberry

    GMC Member

  • GMC Member
  • 557 posts
  • Version:GM8.1

Posted 14 March 2012 - 08:41 PM


I s'pose it would come in handy. It would just be extremely difficult to work with is all. Hah


Might I add that the screenshot you have reminds me of Minecraft. Is that the kind of game you are trying to design?

I realize that is looks a lot like Minecraft. I'd actually come up with this idea before I knew Minecraft existed, and just haven't made any progress on it until lately.
It's not based on Minecraft in any way, it's just due to the graphical limitations of Game Maker. There's no way I'm putting any high-resolution images on cubes. xD

The best method I can think of would be the use of circular functions, such as Sine or Cosine. It provides for smoothness in the swing (as opposed to a fixed speed down and then up)

You can implement it by setting the angle of the sword equal to the result of a sine function, multiplied by the angle you want to swing at, consider:
Posted Image
The y value shown by the curve between 0 and pi is what you want to apply to your angle. (Any further than pi and you will smack yourself in the face)

Here is a shoddy chuck together of an example demonstrating this: Sword Swingery

I hope it is helpful and easy to comprehend ><

Thank you very much! This helps a lot! It's gotten rid of my frustration.
It's a pretty decent way to do things, for now at least. I think at some point I'm going to add in my own animation engine as earlier suggested, which will ultimately replace this way, but I will still credit you for sure.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users