News › Forums › RAIN › General Discussion and Troubleshooting › Convert RAIN.Motion.MoveLookTarget to Vector?
This topic contains 18 replies, has 2 voices, and was last updated by ninjapps 3 weeks, 4 days ago.
-
AuthorPosts
-
February 16, 2022 at 4:18 pm #35897
Hi, I am new to RAIN and love it so far.
I have a little situation where I want to grab the current waypoint “nextStop” as vector3 of a guard which is patrolling over a simple WaypointPath. Long story short I build a script for the main char to go over certain areas which are quite high and where the AI has to follow so I am rebuilding the movement and pathfinder my self and fill in the gaps in the AI tree with custom movement actions rather than the standard move node.
Anyways so i tried getting RAIN.Motion.MoveLookTarget to Vector 3 so I use it in my C# script and I tried various ways such as the one below but either I get a Null or vector 0,0,0
ai.WorkingMemory.GetItem<RAIN.Motion.MoveLookTarget> ("nextStop").transform;
To my understanding RAIN.Motion.MoveLookTarget does not return a Vector 3 but under value in the memory there is Vector Target which not sure if it can be translated to actual world vector coordinates.
Thanks in advance
February 16, 2022 at 8:59 pm #35906To convert a MoveLookTarget to Vector3, simply use the Position property.
MoveLookTarget tTarget = MoveLookTarget.GetTargetFromVariable(ai.WorkingMemory, "nextStop"); Vector3 tPosition = tTarget.Position;
February 17, 2022 at 1:29 pm #35915February 19, 2022 at 7:04 am #35974Hi Prime,
I was looking in the forum and noticed that someone already implemented something similar of what I am trying to do.
http://rivaltheory.com/forums/topic/custom-navigator-for-a-pathfinding-project/
So I am thinking of jumping into this solution. However when I tried to implement it with the new rain I keep getting these errors, and since I am new to rain I got quite lost!
Assets/AstarNavigator.cs(26,34): error CS0115: `RAIN.Navigation.AstarNavigator.ReInit()' is marked as an override but no suitable method found to override Assets/AstarNavigator.cs(46,44): error CS0115: `RAIN.Navigation.AstarNavigator.GetNextPathPosition(bool)' is marked as an override but no suitable method found to override Assets/AstarNavigator.cs(51,44): error CS0505: `RAIN.Navigation.AstarNavigator.GetNextPathWaypoint(bool, RAIN.Motion.MoveLookTarget)': cannot override because `RAIN.Navigation.RAINNavigator.GetNextPathWaypoint(bool, bool, RAIN.Motion.MoveLookTarget)' is not a method Assets/AstarNavigator.cs(69,34): error CS0505: `RAIN.Navigation.AstarNavigator.GetPathToMoveTarget(out RAIN.Navigation.Pathfinding.RAINPath)': cannot override because `RAIN.Navigation.RAINNavigator.GetPathToMoveTarget(bool, out RAIN.Navigation.Pathfinding.RAINPath)' is not a method Assets/AstarNavigator.cs(80,38): error CS0505: `RAIN.Navigation.AstarNavigator.GetPathTo(UnityEngine.Vector3, int, out RAIN.Navigation.Pathfinding.RAINPath)': cannot override because `RAIN.Navigation.RAINNavigator.GetPathTo(UnityEngine.Vector3, int, bool, out RAIN.Navigation.Pathfinding.RAINPath)' is not a method
I know its not a script you guys did but something changed from the Rain version at that time to the latest one.
Can you help?
Thanks in advance.
February 22, 2022 at 1:05 am #36113** UPDATE **
Hi Prime,
I reached out to Aron of A* and he said that some methods got changed since version 2.0.6.2217 of Rain and that possible its just a matter of renaming them (would be great if it was). Any change log I can look at between versions?
Here is the script in question
using RAIN.Motion; using RAIN.Navigation.Graph; using RAIN.Navigation.Pathfinding; using RAIN.Serialization; using UnityEngine; namespace RAIN.Navigation { [RAINSerializableClass] public class AstarNavigator : RAINNavigator { public override RAINPath CurrentPath { get; set; } public override RAINNavigationGraph CurrentGraph { get; set; } public override bool IsPathfinding { get { return true;} } public AstarAIPath astarAIPath; private MoveLookTarget moveLookTarget = new MoveLookTarget(); public override void AIInit() { astarAIPath = base.AI.Body.GetComponentsInParent<AIPathEnemy> (); base.AIInit(); } public override void ReInit() { base.ReInit(); } public override bool OnGraph(Vector3 aPosition, float aMaxYOffset = 0.0f){ return true; } public override Vector3 ClosestPointOnGraph(Vector3 aPosition, float aMaxYOffset = 0.0f){ return aPosition; } public override bool IsAt(MoveLookTarget aPosition) { return true; } public override MoveLookTarget GetNextPathPosition(bool allow3DMovement){ return new MoveLookTarget(); } public override MoveLookTarget GetNextPathWaypoint(bool allow3DMovement, MoveLookTarget moveLookTarget){ // Debug.Log( "GetNextPathWaypoint" ); // Debug.Log( "target=" + astarAIPath.target ); // Debug.Log( "pathTarget=" + this.pathTarget.Position ); if (this.pathTarget == null || !this.pathTarget.IsValid) return (MoveLookTarget) null; astarAIPath.TargetPosition = this.pathTarget.Position; moveLookTarget.VectorTarget = astarAIPath.TargetPoint; // Debug.Log( astarAIPath.TargetPosition ); // Debug.Log( string.Format("({0:F4},{1:F4},{2:F4})", astarAIPath.TargetPoint.x, astarAIPath.TargetPoint.y, astarAIPath.TargetPoint.z)); return moveLookTarget; } public override bool GetPathToMoveTarget(out RAINPath path) { path = null; return true; } public override void RestartPathfindingSearch() { } public override bool GetPathTo(Vector3 position, int maxPathfindSteps, out RAINPath path) { path = null; return true; } } }
February 22, 2022 at 8:07 am #36114I’m not sure where ReInit was being called from, but that method no longer exists. You can just get rid of the method.
Also, I would suggest that you move the code currently in AIInit to BodyInit.
February 22, 2022 at 8:21 am #36115Hi Prime,
I removed it and also placed the code in AllInit to BodyInit as suggested.
Now I only get these errors. Is it possible that these methods are now something else?
Assets/Scripts/Rain+A/AstarNavigator.cs(47,44): error CS0115: `RAIN.Navigation.AstarNavigator.GetNextPathPosition(bool)' is marked as an override but no suitable method found to override Assets/Scripts/Rain+A/AstarNavigator.cs(52,44): error CS0505: `RAIN.Navigation.AstarNavigator.GetNextPathWaypoint(bool, RAIN.Motion.MoveLookTarget)': cannot override because `RAIN.Navigation.RAINNavigator.GetNextPathWaypoint(bool, bool, RAIN.Motion.MoveLookTarget)' is not a method Assets/Scripts/Rain+A/AstarNavigator.cs(70,34): error CS0505: `RAIN.Navigation.AstarNavigator.GetPathToMoveTarget(out RAIN.Navigation.Pathfinding.RAINPath)': cannot override because `RAIN.Navigation.RAINNavigator.GetPathToMoveTarget(bool, out RAIN.Navigation.Pathfinding.RAINPath)' is not a method Assets/Scripts/Rain+A/AstarNavigator.cs(81,38): error CS0505: `RAIN.Navigation.AstarNavigator.GetPathTo(UnityEngine.Vector3, int, out RAIN.Navigation.Pathfinding.RAINPath)': cannot override because `RAIN.Navigation.RAINNavigator.GetPathTo(UnityEngine.Vector3, int, bool, out RAIN.Navigation.Pathfinding.RAINPath)' is not a method
February 22, 2022 at 11:27 am #36116The method signatures have changed slightly. You can take a quick look at the latest API docs to see what the latest signatures look like.
I can’t comment much on the functionality, because I don’t know how Aron’s stuff works, except to say that misc. things may break in RAIN if methods like “GetPathTo”, “IsAt”, and “IsPathfinding” are ignored (like they are in the sample code). They may be fine if you replace ALL of the RAIN movement code, including the Motor and the behavior tree Move node. Otherwise, you will need to fully implement those methods.
February 22, 2022 at 11:30 am #36117Understood. Thanks Prime.
February 22, 2022 at 11:31 am #36118RAIN Navigator API:
http://rivaltheory.com/api/?topic=html/8b8f388c-5deb-9d91-8cb6-504237a2dd6b.htm
General API:
February 24, 2022 at 5:04 am #36169Hi Prime,
Yes adding the “bool allowOffGraphMovement” signature fixed the errors. I only have 1 particular method which I can’t find in the Api. “GetNextPathPosition”
Any idea of what this can be replaced with?
Thanks
February 24, 2022 at 6:43 am #36178That method no longer exists. I believe GetNextPathWaypoint is the replacement.
- This reply was modified 1 month ago by prime.
February 24, 2022 at 7:15 am #36183Thanks Prime! It finally works
Will test it for any issues but looks like its all good.
I placed the final script in the proper post for others.
http://rivaltheory.com/forums/topic/custom-navigator-for-a-pathfinding-project/page/2/#post-36182
Thanks Again!
February 24, 2022 at 8:33 am #36187Hi Prime,
I just quickly tested to upgrade to version 2.1.10 from (2.1.5) and I got the following errors.
Assets/Scripts/AstarNavigator.cs(11,22): error CS0534: `RAIN.Navigation.AstarNavigator' does not implement inherited abstract member `RAIN.Navigation.RAINNavigator.NextWaypoint.get' Assets/Scripts/AstarNavigator.cs(11,22): error CS0534: `RAIN.Navigation.AstarNavigator' does not implement inherited abstract member `RAIN.Navigation.RAINNavigator.NextWaypoint.set'
I can stick with an older version but I would like to update Rain to support Unity 5. I can’t seem to find info on the API ABOUT NextWaypoint.set AND NextWaypoint.get
Ideas?
February 24, 2022 at 10:58 am #36196NextWaypoint is intended to hold the position the AI is moving toward. If the AI is moving along a multi-segment path, then it would be the next segment endpoint. Here’s the very simple implementation in the BasicNavigator:
public override int NextWaypoint { get { return _nextWaypoint; } set { if (CurrentPath != null) _nextWaypoint = Mathf.Clamp(value, 0, CurrentPath.GetLastWaypoint()); } }
-
AuthorPosts
You must be logged in to reply to this topic.