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.

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #35897

    ninjapps
    Participant

    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

    • This topic was modified 1 month, 1 week ago by  ninjapps.
    • This topic was modified 1 month, 1 week ago by  ninjapps.
    • This topic was modified 1 month, 1 week ago by  ninjapps.
    • This topic was modified 1 month, 1 week ago by  ninjapps.
    #35906

    prime
    Keymaster

    To convert a MoveLookTarget to Vector3, simply use the Position property.

    MoveLookTarget tTarget = MoveLookTarget.GetTargetFromVariable(ai.WorkingMemory, "nextStop");
    Vector3 tPosition = tTarget.Position;
    #35915

    ninjapps
    Participant

    Thanks Prime, I always say the best assets are the ones with good support :)

    Cheers

    • This reply was modified 1 month, 1 week ago by  ninjapps.
    • This reply was modified 1 month, 1 week ago by  ninjapps.
    #35974

    ninjapps
    Participant

    Hi 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.

    • This reply was modified 1 month, 1 week ago by  ninjapps.
    • This reply was modified 1 month, 1 week ago by  ninjapps.
    • This reply was modified 1 month, 1 week ago by  ninjapps.
    • This reply was modified 1 month, 1 week ago by  ninjapps.
    #36113

    ninjapps
    Participant

    ** 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;
    		}
    	}
    }
    #36114

    prime
    Keymaster

    I’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.

    #36115

    ninjapps
    Participant

    Hi 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
    #36116

    prime
    Keymaster

    The 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.

    #36117

    ninjapps
    Participant

    Understood. Thanks Prime.

    #36118

    prime
    Keymaster
    #36169

    ninjapps
    Participant

    Hi 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

    #36178

    prime
    Keymaster

    That method no longer exists. I believe GetNextPathWaypoint is the replacement.

    • This reply was modified 1 month ago by  prime.
    #36183

    ninjapps
    Participant

    Thanks 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!

    #36187

    ninjapps
    Participant

    Hi 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?

    • This reply was modified 1 month ago by  ninjapps.
    • This reply was modified 1 month ago by  ninjapps.
    • This reply was modified 1 month ago by  ninjapps.
    • This reply was modified 1 month ago by  ninjapps.
    • This reply was modified 1 month ago by  ninjapps.
    #36196

    prime
    Keymaster

    NextWaypoint 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());
                }
            }
Viewing 15 posts - 1 through 15 (of 19 total)

You must be logged in to reply to this topic.