-
Search Results
-
Topic: Velocity
Hello everyone,
I’m fairly new to Rain, and I seem to be having trouble returning the velocity of an object’s rigidbody.
What I am trying to do:
- Create a cube as the navigator
- Create Rain Navigation Mesh
- Attach an ai and rigidbody to the cube
- Use the ai to walk along a route set up by waypoints <- This is working properly
- Use the rigidbody on the cube so that I can get the velocity of the cube <- Not working properly. It is always returning zero.
- I need the velocity of the cube so that I can tell what direction it is going on the xz axis. I don’t care what direction it is facing, just the direction it is moving towards North, South, East, West.This will be used to position the second object at the same position as the cube and play animations depending on what direction the cube is moving. The position works, I just can’t get the velocity to work when using rain. It works with a regular navigation mesh with a nav mesh agent, but not a Rain mesh with a rigidbody.
I appreciate the help,
Cyrawnis
- This topic was modified 1 day, 1 hour ago by Cyrawnis.
Hi there,
I’ve been following the tutorials that a person on YouTube who goes by the username “CodersExpo” released for public viewing. I’ve been adapting his tutorial into a follower/companion AI for a brawler type game I’m working on.
In his video, he uses two visual sensors to find the player. However, I would like to change this to using a expression (Vector3.Distance(a, b) ?) so that rather than using a visual sensor, if you’re within say 1 unit of the AI, it will pause it’s navigation towards you. This would stop AI jitter, where the AI will approach the target, back off a little, approach, back off, etc.
I’m not sure how to do it though. Do I need to make a custom action to return a value, and if so, what would I write in the custom action code? He explains how to make a “wander” behavior which is good for NPCs that are just filler, but trying to modify that script just seems to break things. Here’s a code dump. A lot of it may be redundant, but I basically retyped it from his video. (It seems that it actually fails instead of success…?)
using UnityEngine; using System.Collections; using System.Collections.Generic; using RAIN.Action; using RAIN.Core; using RAIN.Navigation; using RAIN.Navigation.Graph; [RAINAction] public class FollowPlayer : RAINAction { Vector3 playerPosition = Vector3.zero; float distanceBetweenMeAndPlayer = 0f; public override void Start(RAIN.Core.AI ai) { base.Start(ai); } public override ActionResult Execute(RAIN.Core.AI ai) { playerPosition = ai.WorkingMemory.GetItem<Vector3>("varPlayer"); var found = new List<RAINNavigationGraph>(); do { found = NavigationManager.Instance.GraphsForPoints(ai.Kinematic.Position, playerPosition, ai.Motor.MaxHeightOffset, NavigationManager.GraphType.Navmesh); } while ((Vector3.Distance(ai.Kinematic.Position, playerPosition) < 0.5f) || (found.Count == 0)); ai.WorkingMemory.SetItem<Vector3>("varFollowPlayerTarget", playerPosition); return ActionResult.SUCCESS; } public override void Stop(RAIN.Core.AI ai) { base.Stop(ai); } }
The current setup is this:
- AI has 2 sensors - General Purpose (can see what’s in front of it) and Near (1 unit in front of the AI).
- AI Patrols a route defined using Waypoints.
- If AI can see the player, then it stops patrolling and paths a route to the player.
- If Player is inside the “near” sensor area, the AI will stop and look at the player.
- If Player walks outside the “near” sensor area, the AI will try to follow the player, but if the player gets too far away it will go back to patrolling.
My intended setup is this:
- AI has one visual sensor so it can see things in front of it.
- AI patrols until it sees the player. It registers the player in memory as our target.
- AI calculates the distance between itself and the player.
- If distance above X units, then navigate to the player.
- If distance below/equal X units, then pause.
Ultimately, I want the AI to be able to stay put, so I can for example, walk around it within 1 unit without it suddenly walking off because “Oh, player moved out of my range, I’m going back to patrol logic”.
I’m still green with RAIN, but any snippets are welcome.
Cheers!
Question: Is it possible to create a behavior tree that selects a random waypoint from a Waypoint Network without creating a custom action script node? What would the behavior tree and expressions look like?
I was thinking:
Random Node - Expression Node [varRandomLoc = navigationtarget("Waypoint 1")] - Expression Node [varRandomLoc = navigationtarget("Waypoint 2")] - Expression Node [varRandomLoc = navigationtarget("Waypoint 3")] - Expression Node [varRandomLoc = navigationtarget("Waypoint 4")] //etc.
But your navigationtarget method only works on GameObjects found in the hierarchy, not those in your Waypoint Network component.
Is there a method other than navigationtarget, maybe waypointnetworktarget?So the only way I can think of doing this is by a custom action code to retrieve the waypoints.
public override ActionResult Execute(RAIN.Core.AI ai) { //Script tested on Unity 5.1 with Rain 2.1.11 //Get all of the waypoints in the Waypoint Network WaypointSet tWaypointSet= NavigationManager.Instance.GetWaypointSet("LightBlueNetwork"); //Choose the index of a random waypoint in the waypoint network. int tWaypointIndex = Random.Range(0, tWaypointSet.Waypoints.Count); //Get a reference to the specific cooridinates of the waypoint. Vector3 tRandomWP = tWaypointSet.Waypoints[tWaypointIndex].Position; //Now initialize the Path Target for the Waypoint Path Node. ai.WorkingMemory.SetItem<Vector3>("varLocation", tRandomWP); //This will be passed onto your specific Waypoint Path Target variable for use in the move node. return ActionResult.SUCCESS; }
Thanks in advance!
Hi,
I absolutely love RAIN and have had some reasonable success with it so far, but I’m having a problem finding navigation targets in my code. I am trying to make a custom action that goes to the closest navigation target. I’m missing the code that takes the navigation targets and puts it into my
private WaypointSet navTargets
variable. This is my custom action so far:
using UnityEngine; using System.Collections; using System.Collections.Generic; using RAIN.Action; using RAIN.Core; using RAIN.Navigation; using RAIN.Navigation.Waypoints; [RAINAction] public class GotoClosestWaypoint : RAINAction { private WaypointSet navTargets; private Waypoint gotoPos; public override void Start(RAIN.Core.AI ai) { gotoPos = navTargets.GetClosestWaypoint (ai.Kinematic.Position); ai.Motor.MoveTo (gotoPos.Position); base.Start(ai); } public override ActionResult Execute(RAIN.Core.AI ai) { if (ai.Kinematic.Position == gotoPos.Position) return ActionResult.SUCCESS; else return ActionResult.RUNNING; } public override void Stop(RAIN.Core.AI ai) { base.Stop(ai); } }
- This topic was modified 2 months, 2 weeks ago by inform880.
Hello, I’m currently trying to use a Waypoint Network to move my enemy character around. The player will have the power to obstruct the path of the enemy in some way which I am trying to implement as deleting the connections between waypoints in the network. Unfortunately, when deleting these connections, the enemy character will continue on the path anyway.
I’m trying to write a custom action to fix this so that each time the enemy reaches a node, they will check for a valid connection between the waypoint they are currently at and the one that lies next on the path. I have the check figured out, but I’m just wondering if there’s some easy way to have the enemy re-plan his path. Thank you for any help you can offer!
I have a Waypoint network; that is working fine. But what i wanted was to be able to make decisions on CHOOSING BETWEEN THE MULTIPLE NODES(Waypoints) that originates from the same node using the user input. Any help is deeply appreciated.