News Forums Troubleshooting Moving waypoints at runtime

This topic contains 6 replies, has 3 voices, and was last updated by  Jester 8 months, 3 weeks ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #10878

    littlegames
    Participant

    Hi, I’m fairly new to Rain (although I’m well familiarised with Unity) and I’ve encountered a few problems when trying to move a waypoint at runtime. Apologies if there are blatant mistakes in this code, I’m still getting the hang of Rain!

    Although there will inevitably be some problems in my code, I can’t test it yet because I’m getting compiler errors with some Rain-specific classes. ‘MoveLookTarget’ and ‘WaypointSet’ both ‘do not exist in the current context’ which I guess means I haven’t added the right classes at the beginning of my file, however I’m not sure which ones I could further add; I’ve read the handy documentation and added the ones they seem to require, and I even tried adding every single one and they’re still not being recognised! I’d hugely appreciate a little bit of guidance from someone who could give me a tip as to how to fix this error :)

    Here’s my code (heavily influenced by the samples!):

    using UnityEngine;
    using System.Collections;
    using RAIN.Core;
    using RAIN.Action;
    using RAIN.Navigation;
    [RAINAction]
    public class RainTest : RAINAction
    {
    	private GameObject _avoidTarget;
    	private MoveLookTarget _nextMovePoint;
    	private WaypointSet _wpSet;
    	private static int _wpCurrent = -1;
    	private RaycastHit hit = new RaycastHit();
    	private Ray ray;
    	private Vector3 location;
    	public RainTest()
    	{
    		actionName = "RainTest";
    	}
    	public override void Start(RAIN.Core.AI ai)
    	{
    		if (Input.GetMouseButtonDown (0)) {
    			Debug.Log ("clicked");
    			ray = Camera.main.ScreenPointToRay (Input.mousePosition);
    				if (Physics.Raycast (ray, out hit, 10000)) {
    					Vector3 (hit.point.x, (hit.point.y), hit.point.z);
    					_wpSet = NavigationManager.instance.GetWaypointSet ("Waypoint Route");
    					//Create the movelook object and define the position
    					_nextMovePoint = new MoveLookTarget () { VectorTarget = location };
    					ai.Motor.moveTarget = _nextMovePoint;
    					base.Start (ai);
    				}
    		}
    }
    	public override ActionResult Execute(RAIN.Core.AI ai)
    	{
    		if (!ai.Motor.IsAtMoveTarget)
    		{
    			ai.Motor.Move();
    			return ActionResult.RUNNING;
    		}
    		return ActionResult.NONE;
    	}
    	public override void Stop(RAIN.Core.AI ai)
    	{
    		base.Stop(ai);
    	}
    }
    • This topic was modified 9 months ago by  littlegames.
    #10881

    prime
    Keymaster

    MoveLookTarget requires RAIN.Motion
    WaypointSet requires RAIN.Navigation.Waypoints

    #10882

    prime
    Keymaster

    What are you trying to accomplish with your code? Just moving to a location that the player clicks?

    #10899

    littlegames
    Participant

    Thanks so much, that’s solved it!

    Yes, I know I could easily move to a location without waypoints at all by just setting a location and moving in a straight line, but I really like RAIN’s pathfinding and obstacle avoidance. Is there a simpler way to do this?
    Thanks

    #11606

    Jester
    Keymaster

    We will have dynamic obstacle avoidance in a coming patch that will allow the navigation mesh to refresh at runtime.

    Also check out our new tutorial series. http://rivaltheory.com/forums/topic/get-started-with-rain-2-0-10-video-walkthrough/

    Let me know if you have any other questions.

    Best,
    Jester

    #11632

    littlegames
    Participant

    Thanks for the response Jester. The tutorials look good - I’ll have a look tomorrow and hopefully it’ll teach me many new things.

    #11743

    Jester
    Keymaster

    They surely will. Let us know if you have any questions.

    Best,
    Jester

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

You must be logged in to reply to this topic.