News › Forums › RAIN › General Discussion and Troubleshooting › Two issues.
This topic contains 3 replies, has 2 voices, and was last updated by Generaallucas 3 months, 2 weeks ago.
-
AuthorPosts
-
November 6, 2022 at 12:41 pm #33946
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_yam8MKyICan you help me out with these two issues?
Thanks in advance.
November 6, 2022 at 5:51 pm #33980Are you using Root Motion movement?
November 6, 2022 at 6:02 pm #33981Since 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.
November 8, 2022 at 5:05 pm #33999Sorry 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!
-
AuthorPosts
You must be logged in to reply to this topic.