-
Search Results
-
Hello, everyone!
Been trying to create a simple traffic system using RAIN AI.
I plan to make cars travel along a set of waypoints that I intend to use as the “road”.
I also wanted it so that they stop when they detect another car in front of them
However, I’ve been having problems trying to get the AI to continue moving to the next waypoint.Somehow when they are less than halfway through to the next waypoint and they are interrupted
by the car in front, they return to their previous waypoint. When they are more than halfway
through, they skip the current waypoint and moves to the next.I’m having a hard time looking for more information in the wiki and would like some help.
Thanks in advance!
Here is a gif depicting my problem.
Here is a picture of the behavior tree I used.
Here is the XML export of my Behavior Tree.
<behaviortree version="1.1" repeatuntil="" name="Car2BT" debugbreak="False"> <sequencer usepriorities="False" repeatuntil="" name="root" debugbreak="False"> <parallel tiebreaker="fail" succeed="all" repeatuntil="" priority="" name="parallel" fail="any" debugbreak="False"> <detect sensor=""Car Sensor"" repeatuntil="running" name="detect car" matchtype="best" entityobjectvariable="frontCarForm" debugbreak="False" consistent="True" aspectvariable="frontCarAspect" aspectobjectvariable="frontCarMountPoint" aspect=""Car"" /> <waypointpatrol waypointsetvariable=""TrafficPath"" waypointactiontype="patrol" traversetype="loop" traverseorder="forward" repeatuntil="" pathtargetvariable="" name="waypointpatrol" movetargetvariable="moveTarget" debugbreak="False"> <selector usepriorities="False" repeatuntil="" name="selector" debugbreak="False"> <constraint repeatuntil="" priority="" name="stop - car detected" debugbreak="False" constraint="frontCarAspect != null" /> <constraint repeatuntil="" priority="" name="move - no car detected" debugbreak="False" constraint="frontCarAspect == null"> <move turnspeed="" repeatuntil="" name="move" movetarget="moveTarget" movespeed="10" facetarget="" debugbreak="False" closeenoughdistance="" closeenoughangle="" /> </constraint> </selector> </waypointpatrol> </parallel> </sequencer> </behaviortree>
Topic: Animal Wandering
Hi, I would like to know how I could make an AI (animal) wander around inside my navigation mesh? (without waypoints, I mean it would be completely random )
Thank you.- This topic was modified 4 months, 1 week ago by Thrisboss.
I’m attempting to write a custom MoveTo action. As a result I’m seeing some confusing results in the internal AI navigation.
I’m asking the Navigator for a valid path to the active MoveTarget (eg. the player) using ai.Navigator.GetPathToMoveTarget(), and then navigate the set of ‘waypoint nodes’ defined in the resulting path.
If I call ai.Motor.IsAt() beforehand, then the subsequent ai.Navigator.GetPathToMoveTarget() returns a valid path and is successful.
However, if I don’t call ai.Motor.IsAt(), then the exact same scenario fails to return a valid path.
I basically want to ask the Navigtor “Give me a new valid path from my current location to the target”, and then navigate the waypoints via an enumerator. Is there some other way I should be attempting to do this?
Sincerely.
In my journey called “test if everything in RAIN can be created programatically”, I am facing another problem.
So far, I have accomplished these things from the code (with help of this great community!):
*attach AI rig
*create route
*create behavior tree that will follow the route and set it to the actorheres what the script looks like now:
using UnityEngine; using System.Collections; using RAIN; public class RAINTest : MonoBehaviour { GameObject m_AIParent; RAIN.Core.AIRig m_AIRig; void Start() { // AI parent GameObject m_AIParent = new GameObject("AI"); m_AIParent.transform.parent = gameObject.transform; m_AIParent.transform.localPosition = Vector3.zero; // attach AI rig m_AIRig = m_AIParent.AddComponent<RAIN.Core.AIRig>(); m_AIRig.AI.Body = gameObject; /* NOT WORKING // animation setup m_AIRig.AI.Animator = new RAIN.Animation.MecanimAnimator(); // motor setup RAIN.Motion.MecanimMotor mecanimMotor = new RAIN.Motion.MecanimMotor(); m_AIRig.AI.Motor = mecanimMotor; mecanimMotor.UseRootMotion = false; RAIN.Motion.MecanimMotor.MotorParameter velocityXParameter = new RAIN.Motion.MecanimMotor.MotorParameter(); velocityXParameter.motorField = RAIN.Motion.MecanimMotor.MotorField.VelocityX; mecanimMotor.AddForwardedParameter(velocityXParameter); RAIN.Motion.MecanimMotor.MotorParameter velocityZParameter = new RAIN.Motion.MecanimMotor.MotorParameter(); velocityZParameter.motorField = RAIN.Motion.MecanimMotor.MotorField.VelocityZ; mecanimMotor.AddForwardedParameter(velocityZParameter); */ // create route dynamically GameObject route = new GameObject("route"); route.transform.position = Vector3.zero; // attach waypoint rig RAIN.Navigation.Waypoints.WaypointRig waypointRig = route.AddComponent<RAIN.Navigation.Waypoints.WaypointRig>(); // it's a route waypointRig.WaypointSet.SetType = RAIN.Navigation.Waypoints.WaypointSet.WaypointSetType.Route; // random color //waypointRig.WaypointSet.NetworkColor = RAINEditor.RAINEditorUtility.PickRandomVisualColor(); // waypoints RAIN.Navigation.Waypoints.Waypoint wp0 = new RAIN.Navigation.Waypoints.Waypoint(); wp0.Position = new Vector3(3,0,0); RAIN.Navigation.Waypoints.Waypoint wp2 = new RAIN.Navigation.Waypoints.Waypoint(); wp2.Position = new Vector3(-3,0,0); // add 'em to the route waypointRig.WaypointSet.AddWaypoint(wp0); waypointRig.WaypointSet.AddWaypoint(wp2); waypointRig.Serialize(); // create behavior tree dynamically RAIN.BehaviorTrees.BTWaypointNode tRoot = new RAIN.BehaviorTrees.BTWaypointNode() { waypointSetVariable = RAIN.Representation.ExpressionParser.Parse("route"), waypointActionType = RAIN.BehaviorTrees.BTWaypointNode.WaypointActionType.PATROL, traverseType = RAIN.BehaviorTrees.BTWaypointNode.WaypointTraverseType.PINGPONG, traverseOrder = RAIN.BehaviorTrees.BTWaypointNode.WaypointTraverseOrder.FORWARD, moveTargetVariable = "waypointTarget" }; tRoot.AddChild(new RAIN.BehaviorTrees.Actions.MoveAction() { moveTargetExpression = RAIN.Representation.ExpressionParser.Parse("waypointTarget") }); // set it RAIN.Minds.BasicMind basicMind = m_AIRig.AI.Mind as RAIN.Minds.BasicMind; basicMind.BehaviorRoot = tRoot; m_AIRig.Serialize(); } void Update() { } }
you can attach this script to capsule e.g. and even it has no AI before the game start, it will work properly, everything will be created programatically at runtime.
“SO WHAT IS YOUR PROBLEM?!”
the problem is when I want to have fully animated character (a soldier) instead of simple capsule.
When the AI rig is created, the AI has basic motor and basic animator set as default, and I want to change them both to mecanim variants. (see the commented out section of code named “NOT WORKING”).just to make you sure: when I do the same thing by “clicking in unity editor”, everything’s fine, and the soldier is animating as he walks.
“SO WHAT DOES THE CODE DO?!”
when I comment out the problematic section of code, these two errors starts rolling:NullReferenceException: Object reference not set to an instance of an object RAIN.Motion.MecanimMotor.UpdateMotionTransforms () RAIN.Core.AI.Pre () RAIN.Core.AIRig.AIUpdate () RAIN.Core.AIRig.Update ()
and
NullReferenceException: Object reference not set to an instance of an object RAIN.Animation.MecanimAnimator.UpdateAnimation () RAIN.Core.AI.Post () RAIN.Core.AIRig.AILateUpdate () RAIN.Core.AIRig.LateUpdate ()
“HAVE YOU CAME UP WITH SOMETHING ALREADY?!”
yes, I have noticed that when you do the same thing (changing the animator or motor or both at runtime) with ordinary created AI (I mean: by “clicking in Unity editor”), you got the same errors. so my final question is simply:how to change motor and animator at runtime?
- This topic was modified 5 months, 3 weeks ago by Martin Cmar.
Topic: AI won't go to waypoint