playMaker

Author Topic: 2d weapon animation  (Read 2434 times)

amirkhan

  • Playmaker Newbie
  • *
  • Posts: 17
2d weapon animation
« on: November 16, 2018, 09:28:40 AM »
I'm trying to make a platform game, the character starts with basic animation (idle,walk, jump), but then the player grabs a weapon so the sprite changes (now it has the weapon on his hand) and so does the animation. My question is how to make that transition when the player has the weapon, how to I change the sprite of the character and the animation?

GonerGames

  • Junior Playmaker
  • **
  • Posts: 53
Re: 2d weapon animation
« Reply #1 on: November 16, 2018, 11:11:37 AM »
Depending on how your 2D charater is setup using Unity's Anima2D might be a good option for you. It allows you to set up a skeleton frame work for your 2D characters. This would allow you to dynamically adjust your weapons around the bone framework. This is a bit of effort to setup, but is far more flexible for runtime operations.

Anima 2D is free on the asset store and here is a link to the youtube tutorial series for Anima 2D.
Anima Youtube

Hope this helps.

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: 2d weapon animation
« Reply #2 on: November 16, 2018, 05:50:19 PM »
For platformer, you have three general options:

— depending on what exactly is meant by “2D”. You can use full 3D, but use the same perspective and trappings like a 2D platformer, so it functionally is 2D, but is technically build in 3D. You can also mix and match. Use some sprites, or 2D tech (colliders etc) but on 3D models. Look for Romi Fauzi on YouTube.

— skeletal 2D, as Goner Games points out. This can be done in at least two ways: you can make body parts of a character and through rotation around pivots make it move (like a cardboard puppet). The parts themselve can be moved, or more conmon, a skeleton is animated, the bones are invisible, but the body parts are put as child underneath. The other technique is similar, but uses mesh deformation of a sprite attached to the bone rig. Unity has this in the works, I wouldn’t use Anima2D at this point. I myself use Puppet2D.

— Finally, classic frame animation technique, known as sprite animation, where the movement is drawn onto a series of images (sprites), as it’s done in cartoons and most older 2d games like Super Mario Bros, Megaman etc.

How the weapon animation works totally depends on which technique you use. I have such a system, and in my case, the skeletal 2d character has an empty game object as a mount/bind point at the hand, under which I can add a weapon so that when the weapon transform is zero, it fits exactly.

In playmaker, I send off a bool to the animator that the character is now armed. One way to do this is to have a complete movement set for armed and unarmed, and by condition (e.g. isArmed is true/false) switch using either one. But in my case, I also use animation layers, so that only hands and few animations are overwritten when the character is armed.

The procedure is similar when you go 3D, with bind points, and transition animations and conditions in mechanim.

When you use oldskool sprite animation, you must make all animations also with the weapon equipped (i.e. drawn onto the sprite) plus potential “switch” weapon animation clips. But you can also try to mix and match techniques. Then, as usual, the animations go into animation clips, equip_armed, equip_unarmed, idle_armed, idle_unarmed, jump_armed etc. And when some condition is met, you switch animation clips around typically in the mechanim animator. How to do this, study Unity’s 2D platformer project and watch tutorials.