News › Forums › Troubleshooting › Moving waypoints at runtime
Tagged: Error, RAIN, Waypoints, waypointset
This topic contains 6 replies, has 3 voices, and was last updated by Jester 8 months, 3 weeks ago.
-
AuthorPosts
-
March 29, 2022 at 12:26 am #10878
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.
March 29, 2022 at 1:33 am #10881MoveLookTarget requires RAIN.Motion
WaypointSet requires RAIN.Navigation.WaypointsMarch 29, 2022 at 1:34 am #10882What are you trying to accomplish with your code? Just moving to a location that the player clicks?
March 29, 2022 at 2:04 pm #10899Thanks 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?
ThanksApril 9, 2022 at 6:32 pm #11606We 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,
JesterApril 10, 2022 at 12:42 am #11632Thanks for the response Jester. The tutorials look good - I’ll have a look tomorrow and hopefully it’ll teach me many new things.
April 11, 2022 at 5:00 pm #11743They surely will. Let us know if you have any questions.
Best,
Jester -
AuthorPosts
You must be logged in to reply to this topic.