This topic contains 3 replies, has 2 voices, and was last updated by  Generaallucas 3 months, 2 weeks ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #33946

    Generaallucas
    Participant

    I have a character that I want to put on a basic patrol. This character is rigged and I use mecanim, with a speed and direction variable (both floats) and a run variable (boolean). Direction goes from -1f to 1f (left to right) and thus determines the direction in which the character is walking through a blendtree. This is the Base Layer.Walking blend tree. However, I cannot find in tutorials or on the web how to integrate this direction variable and use it within RAIN.

    Second issue; Now, I can use the speed variable and it allows me to let my character walk through the behavior panel. (root->animation) I’m now trying to get my character to follow a waypoint path that I made(root->waypoint path->move), but it only walks forward and has no indication to move in the path.

    I have done the following things:
    - Used Waypoint Route in root->waypoint path and named it after the path in the scene. I did try to use quotation marks, but that only gave a lot of exception errors.
    - Put animate AFTER waypoint path->move as a direct child of root, as by instruction of this tutorial https://www.youtube.com/watch?v=vW_yam8MKyI

    Can you help me out with these two issues?

    Thanks in advance.

    #33980

    prime
    Keymaster

    Are you using Root Motion movement?

    #33981

    prime
    Keymaster

    Since Mecanim is receiving a speed parameter (presumably directly from the MecanimMotor in RAIN) you don’t need a separate Animate node under the Waypoint Route. Just the Move will suffice.

    Since your direction goes from -1 to 1, you’ll need to make a change - either to your blend tree or to RAIN - in order to feed values within that range. I typically recommend a change to the blend tree, but either way will work.

    - You will probably want to use the TurnAngle parameter from the MecanimMotor in order to drive turning in Mecanim. TurnAngle will give you the total remaining angle the AI needs to turn (-180 to 180).
    - If you change your blendtree to use a range of -180 to 180, then you don’t need to make any changes in RAIN. Instead, just select TurnAngle from the Add Parameter pulldown on your MecanimMotor. Set the parameter name to the name of your Mecanim parameter (Direction?) The MecanimMotor will then constantly set your parameter to the current TurnAngle.
    - If you don’t want to change your blendtree, then you will need to add a little bit of code to scale the TurnAngle between -1 and 1. You can do that using a RAIN Custom AI Element. Create a file called MecanimHelper.cs and put this code in it. Then go to the Custom tab on your AI (looks like a pencil) and add Mecanim Helper (it will appear after Unity compiles your new file.)

    using UnityEngine;
    using System.Collections;
    using RAIN.Core;
    using RAIN.Serialization;
    using RAIN.Motion;
    [RAINSerializableClass, RAINElement("Mecanim Helper")]
    public class MecanimHelper : CustomAIElement 
    {
        private MecanimMotor _motor;
        public override void BodyInit()
        {
            base.BodyInit();
            _motor = AI.Motor as MecanimMotor;
        }
        public override void Act()
        {
            base.Act();
            if (_motor != null)
                _motor.UnityAnimator.SetFloat("Direction", _motor.TurnAngle / 180f);
        }
    }
    • This reply was modified 3 months, 2 weeks ago by  prime.
    #33999

    Generaallucas
    Participant

    Sorry for the late response.

    I’ve played around with your code, and adjusted the blend tree so the division by 180 wouldn’t be necessary, and it works! Cheers, mate! Thanks for the help!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.