Git Product home page Git Product logo

playcanvas-animator's Introduction

PlayCanvas Animator

This is a useful animator script that can be used similar fashion to the AvatarMask and Layers on Unity3d.

Usage

You can use this script solely by altering this script's attributes and simply hooking in to the PlayCanvas event system to interact with your new AnimatorControl component.

First, you need to assign the script to your player entity. This doesn't necesarilly have to be the entity with a mesh attribute, so you can use your collider entity parent (if you have) one, if you'd like.

Attributes

Set your "Skinned Mesh" to your mesh entity (probably a character of some sort), and your "Animation Entity" to the entity that contains an Animation component, marked with all of the animations you'll be utilizing for your character.

You'll also need to modify your root layer bones (Spine and Hips) based on your model's skeleton type. This will vary, and you may have to list all of the bones in your model to figure out the exact name of the spine and hip(s) bones.

If you don't know your model's bone structure, you can list all of it's bones by sending this event (which will log it's bone structure):

this.app.fire('bone:list');

And this will respond with something that looks similar to this (if you have a humanoid character:

[Insert Example Screenshot of Bone Listing]

Note that this will only work if the script is correctly attached to a MeshComponent and has the SkinnedMesh attribute ascribed.

Examples

var AnimationBlending = pc.createScript('animationBlending');

AnimationBlending.states = {
    idle: {
        animation: 'male.json'
    },
    punch: {
        animation: 'male_uppercut_jab.json'
    }
};

// initialize code called once per entity
AnimationBlending.prototype.initialize = function() {
    this.blendTime = 0.2;

    this.setState('idle');

    this.app.keyboard.on(pc.EVENT_KEYDOWN, this.keyDown, this);
    this.app.keyboard.on(pc.EVENT_KEYUP, this.keyUp, this);
};

AnimationBlending.prototype.setState = function (state) {
    var states = AnimationBlending.states;

    this.state = state;
    // Set the current animation, taking 0.2 seconds to blend from
    // the current animation state to the start of the target animation.
    this.entity.animation.play(states[state].animation, this.blendTime);
};

AnimationBlending.prototype.keyDown = function (e) {
    if ((e.key === pc.KEY_P) && (this.state !== 'punch')) {
        this.app.fire('animator:update', 'punch');
    }
};

AnimationBlending.prototype.keyUp = function (e) {
    if ((e.key === pc.KEY_P) && (this.state === 'punch')) {
        this.setState('idle');
    }
};

Table of Contents

Roadmap

playcanvas-animator's People

Contributors

noahcoetsee avatar yhydra avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.