News › Forums › RAIN › General Discussion and Troubleshooting › Move in 3d space
Tagged: Move motor navigation
This topic contains 8 replies, has 2 voices, and was last updated by prime 5 months ago.
-
AuthorPosts
-
February 5, 2023 at 4:39 pm #35544
Hi!
I am currently working on a Shark AI and I am trying to decide which is the best way to move it. It should me able to move not only in xz but in y as well!So far I thought I would use rain just for the sensors and do all the movement in code, but maybe there is a nice way to achieve this with navigation meshes or way points? Maybe create a custom motor instead?
The Shark should wander around a zone and when noise is detected go to the sensed element and wander around it for a bit ad wellPlease advice!
February 6, 2023 at 7:29 am #35553Seems like you could do this with Allow 3D Movement turned on in your Basic Motor, plus Allow Off Graph Movement. I’m guessing you don’t need a navmesh. I’m not certain if you want to Allow 3D Rotation for your shark. I would probably start without it and see how it looks.
February 6, 2023 at 7:34 am #35554Thanks for the reply, I will give it a try this weekend and see how it goes.
What do you mean about the navmesh? How can I move the shark without a navmesh and the basic motor, by just creating navigation waypoints?
February 6, 2023 at 7:37 am #35555I’m assuming the shark is moving through water - which usually doesn’t have fixed obstacles. You wouldn’t need a navmesh or waypoints in open space. You would just specify where you want the shark to move, then go there.
Feel free to use a navmesh or a waypoint network if you do have obstacles that you want to work around, but they aren’t required. Keep in mind that a navmesh represents a walkable surface, not a 3D volume, so it may or may not be useful depending on your setup.
February 6, 2023 at 7:55 am #35556Maybe I can leave it without any kind of navmesh but use some simple waypoints to go around the very few obstacles.
I will update this on the weekend after a bit of research!
February 8, 2022 at 7:36 am #35571After reading a bit further, I am considering using a simple move from A to B command as suggested + adding some steering behaviour to avoid occasional collisions with rocks or whatever.
Does RAIN support that out of the box? Do I have to do my own? in that case, where should I “plug” it?
February 8, 2022 at 9:53 am #35576RAIN doesn’t support that type of collision avoidance out of the box. It shouldn’t be too hard though, if you are not worried about staying on a NavMesh. I probably wouldn’t worry about steering behaviors either - instead I would pick an intermediate target (to the right or left of the collision), move there, and then resume moving to the destination. Steering behaviors are fine for boids/birds/flocking, but in my experience things always seem too “slidy” when you use them for character movement. (I’m unsure about sharks in water though… maybe it would be fine?)
February 8, 2022 at 2:58 pm #35582Probably not the best solution but here is some code:
public class WaterNavigator : BasicNavigator { public Vector3 TargetPosition { get; set; } public float deltaDistance = 0.5f; public override MoveLookTarget GetNextPathWaypoint (bool allow3DMovement, bool allowOffGraphMovement, MoveLookTarget cachedMoveLookTarget) { MoveLookTarget waypoint = base.GetNextPathWaypoint (allow3DMovement, allowOffGraphMovement, cachedMoveLookTarget); Vector3 from = this.AI.Body.transform.position; Vector3 to = TargetPosition; while(Physics.Raycast(from, (to-from).normalized, (to-from).sqrMagnitude)) { to.y += deltaDistance; } waypoint.VectorTarget = to; return waypoint; } public override RAINNavigationGraph GetPathGraphFromPositions (Vector3 aPoint1, Vector3 aPoint2) { if(aPoint1 != aPoint2) { TargetPosition = aPoint2; } return null; } }
Basically this will create mid waypoints and avoid obstacles swimming up.
Choosing between swiming up or left/right seems more complicated without a navmesh Will see how this behaves.On the other hand you were right, 3D rotation does not look well, is there any way to smooth it? or clamp it
February 9, 2022 at 10:11 am #35590You could smooth or clamp 3D rotation by creating a custom motor, much like your custom navigator.
-
AuthorPosts
You must be logged in to reply to this topic.