News Forums RAIN General Discussion and Troubleshooting Move in 3d space

This topic contains 8 replies, has 2 voices, and was last updated by  prime 5 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #35544

    MephestoKhaan
    Participant

    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 well

    Please advice!

    #35553

    prime
    Keymaster

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

    #35554

    MephestoKhaan
    Participant

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

    #35555

    prime
    Keymaster

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

    #35556

    MephestoKhaan
    Participant

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

    #35571

    MephestoKhaan
    Participant

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

    #35576

    prime
    Keymaster

    RAIN 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?)

    #35582

    MephestoKhaan
    Participant

    Probably 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

    #35590

    prime
    Keymaster

    You could smooth or clamp 3D rotation by creating a custom motor, much like your custom navigator.

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

You must be logged in to reply to this topic.