JU TPS Documentation
  • 🤩Welcome to JU TPS
  • 😄Quick Start
    • How to start a new scene
    • How to create a JU Character / Reskin Default Character / Setup New Characters
      • Ragdoll
      • Damageable Body
      • Physical Damage
      • Body Leaning Setup
      • Taking Damage / Healing
      • Footstep System
      • Resizable Capsule Collider
    • 📦 Addon Installer
  • 🎮Game Development
    • Game Styles
      • Third Person Shooter Style
      • First Person Shooter Style
      • Top Down Style
      • 2.5D Sidescroller Style
      • ⚠️Important Info About Cross-Plataform
    • Controls / Inputs
      • JU Input Manager
      • Input Events
    • How to create a Mobile Game with JU TPS
      • Mobile Inputs
    • How to load scene
      • Scene Controller
    • How to use Cover System
    • How to use inventory and add items
      • Inventory in UI
      • How to switch between items
      • How to align weapon rotation
    • How to create weapons and items
      • Prevent gun clipping through walls
      • Creating Projectiles/Bullets
    • How to use Dual Wielding System
    • How to use Armor/Cloth System
    • How to use Vehicle System
      • Standard Vehicle Configuration
      • How to create a Car Controller
      • How to create a Motorcycle Controller
      • Vehicle Engine Sounds
      • Coding Custom Wheeled Vehicles
      • How to enter and exit from a vehicle
    • How to use Gravity Switching
    • How to use Actions/Skill and Animation Events
      • JU TPS State Machine Behaviours
      • JUTPSActions Lib Scripting Reference
    • Camera State Trigger
    • How to use Enemies AI
    • How to use Vehicles AI
  • ⚙️Tools, Utils and Tutorials
    • General Tutorials
      • How to do Ragdoll Fall with Input Event
      • How to disable FPS Aim Mode / Scope / Iron Sight Aim
    • Auto Scripts
    • Icon Generator Tool
    • Destructible Objects System
      • Fracture Generator Tool
    • Pixel Quality Scaler
    • Camera Shake
    • Slow Motion
    • Gizmo Drawer
  • ▶️Video Tutorials
    • How to use JU TPS
  • 💬Discord Community
  • ❓Support | Help
  • 📍Roadmap
  • 🔃Change Log
  • 📦Official Addons
Powered by GitBook
On this page
  • How to play a animation without coding
  • How to create a Action/Skill script
  • Animation Event System
  1. Game Development

How to use Actions/Skill and Animation Events

PreviousHow to use Gravity SwitchingNextJU TPS State Machine Behaviours

Last updated 2 years ago

How to play a animation without coding

You can play animations without code with the Simple Play Motion component in just two steps:

1- Create a Animation State on a Custom Action Layer and assign an animation:

It is recommended to create a copy of the default animator controller to edit it, so if you make a mistake in some edition you can easily return to the original file.

2- Add Simple Play Motion component to your JU Character and configure it:

Simple Play Motion Properties
Description

Action Duration

Motion duration

Enter Transition Speed

Enter animation state speed

Exit Transition Speed

Exit animation state speed

Target Layer

Body part to play animation, if you look at the Custom Action Layers of the default Animator Controller, each layer controls a different body part

Animator State Name

Animation state name

Start Motion At

You can cut the beginning of the animation with this option

Input To Call Action

Input to start action

Force Fire Mode

While the action is playing, set FireMode to true

Force No Fire Mode

While the action is playing, set FireMode to false

Block Character Locomotion

While the action is playing, the character does not move

Start Action Even State Is Playing

With this option it is possible to start the action even if it is already playing

Result:

How to create a Action/Skill script

JU TPS has classes and scripts to create actions, emotes or abilities.

The JUTPSAction class is made to interact with the JU Characters system, it has references of JU Character Controller, Animator, Rigidbody, Collider and Camera.

JUTPSAnimatedAction is made for actions involving animations, and has functions to interact with the default JU TPS Animator Controller.

To use these classes you need to make your skill script inherit the classes:

See sample code below:

SkillExample.cs
using UnityEngine;
// > Import JU Input System Lib
using JUInputSystem;

// > inherit the JUTPSAnimatedAction class
public class SkillExample : JUTPSActions.JUTPSAnimatedAction
{
    [Header("Skill Variables")]
    public string AnimationStateName;

    void Start() { SwitchAnimationLayer(ActionPart.FullBody); }

    //Called every frame
    public override void ActionCondition()
    {
        if (JUInput.GetButtonDown(JUInput.Buttons.AimingButton) && IsActionPlaying == false)
        {
            //Start action and play animation
            StartAction();
            PlayAnimation(AnimationStateName);
        }
    }
    //Called every frame while action is playing
    public override void OnActionIsPlaying()
    {
        //Force NO FiringMode
        TPSCharacter.FiringMode = false;
        //Make character fly
        rb.velocity = transform.up * 4;
        //Make the character look in front of the camera
        TPSCharacter.transform.LookAt(cam.transform.forward * 100);
    }

    //Called on action start
    public override void OnActionStarted()
    {
        //Store current item in use
        SetCurrentItemIndexToLastUsedItem();
        //Disable Item
        DisableItemOnHand();
    }
    //Called on action end
    public override void OnActionEnded()
    {
        //Re-equip last used item
        EnableLastUsedItem();
    }
    
    // >> Function to be called by JU Animation Event Receiver <<
    public void MagicAttack()
    {
        Vector3 spawnPos = anim.GetBoneTransform(HumanBodyBones.RightHand).position + transform.forward * 0.3f;
        GameObject magic_attack = Instantiate(MagicAttackParticle, spawnPos, transform.rotation, transform);
        Destroy(magic_attack, 10);
    }
}

This code plays in an animation (line 16 to 21) and makes the character fly and look in front of the camera (line 26 to 31), it also unequips items when the action starts and equips the last used item when the action ends (line 35 to 47). See the result:

Animation Event System

It is possible to invoke functions through Animator easily without having to create animation events directly in animations.

1- Add the JU Animation Event to your animation state and give your event a name, and configure at what time the component will call your event(Duration propertie)

2- Add the JU Animation Event Receiver, create an event with the same name you put in the JU Animation Event, and in the Event call the function you want:

See the result:

The code also has a function to spawn a magic attack at character hand position, but it won't do anything by itself, to make the magic spell attack work, let's go to the .

🎮
next topic
✅ Animation state running every time I press the G key