Forum rules - please read before posting.

Custom movement and rotation off Navmesh?

Hi. I want to move my character to a point clicked anywhere in the 3d environment without following Navmesh pathing. For example, I want to click on the ceiling, and then walk on it inverted.

How can I override / extend the movement to allow move/rotate to my click on a navmesh layer as though the character can fly? I have the code working in my own project, but do not know how to get this to work in AC which I purchased yesterday :D.

Ideally, I want to use the rotate before move functionality also. Navmeshes do not work past 60 degree angles as far as I know, and the navmesh is created on the top of the area, yet I require it underneath. Therefore I set the game object layer to Navmesh, but I dont mark it as Navmesh Static, because I don't want to use the pathing. Basically, a baked path is pointless for my purpose.

Thanks in advance for any ideas or solutions!

Comments

  • Welcome to the community, @Lokstock.

    First of all, you'll want to look into Mesh Collider-based pathfinding - the 3D Demo makes use of this and essentially gives you exact control over the shape and orientation of your NavMesh.

    AC does give you a little functionality for non-floor walking in the form of the Ignore gravity? options on the Player component and the Character: Move to point Action.  However, the need for rotations as well make this too complex a problem, I think, for AC's standard movement system.

    At any time, AC's characters can be controlled via custom script - by setting their Motion control setting to Manual.  You can then read functions within their scripts to determine where AC intends for them to be, and make use of them accordingly.

    You can find a practical example tutorial about writing custom motion controllers here.  While every case and need is different in terms of complexity, I hope that it's not too taxing given that you already have a script for the behaviour you want.  I would say that it's certainly recommended to understand the "AC way" of doing things before attempting any changes - good luck!
  • Thanks Chris. I appreciated your quick reply. I have been looking into this for a few days and unfortunately I am not much closer to a result. I can't clearly explain all of the different things I have tried. There is a lot of code and classes to look through. I have had varying levels of success, but nothing that really works as intended. Outside of AC, without pathfinding, what I am trying to do is simple: Click on something set to the right layer, and then rotate and move the player to the point.

    I tried an inverted cube following http://www.adventurecreator.org/tutorials/mesh-collider-pathfinding. This kind of worked with movement on auto. But I don't think that will really work long term. I tried extending the navmeshengine, which I probably did wrong. I tried a custom controller and motioncontroller. I tried to ignore isGrounded and AffectY and removed the lock rotations. I am able to get the character rotate before moving, and some times move, but these are both wildly inaccurate in what seems a random manner. The movement becomes rather strange and gittery, and the point it tries to face is often not very close, and will never rotate to face in a downward manner. I may be able to get there eventually but I am growing frustrated mostly at trying to grasp the basics of how it all works together. I have not found just yet why the player can't look down, but I might in a moment. 

    If you could, I would appreciate some pointers on how you might achieve what I am after. I am unable to find similar code on the forums yet. I have followed your above advice as best I could. There is, it seems, many things that prevent movement in the manner I am after.  char.GetTargetPosition() gives me the info I need, I just need to be using the correct movement and navmesh details I think. 
  • I apologise for your frustration, though I should first mention that what you're looking to do is quite complex (the rotation in particular) and not something that AC is designed to do by itself.  However it should be possible with the right custom scripts.

    The MeshCollider method is a good base, in that it allows you to create NavMeshes of any shape and orientation.  However, the built-in method will still try to create a pathfinding algorithm around it, and will always expect the player to be on the same plane (ie. no floating in between).

    The first thing to do is to probably create a new pathfinding script that basically avoids any pathfinding at all.  Duplicate the MeshCollider script and remove everything inside GetPointsArray except for code that causes it to return targetPos as a single-entry Vector3 array.  This function returns the locus of the path, so just returning the targetPos (target position) will essentially remove pathfinding.  How to then make use of this alternative script is covered in Section 12.4 of the Manual.

    You'll be ready to move on when GetTargetPosition always returns the correct position.  At this point, you'll be ready to go with a custom motion controller.  Make sure that the Player's Motion control setting is set to Manual, as rotation will need to be overridden as well as position.  Your own motion contoller code will have to move the player according to the target position, but know that there is currently a bug with AC that causes conflicts with Rigidbody characters that use custom motion controllers.  Until v1.53 is released, you can fix this in one of two ways:

    1) Remove the Rigidbody from the character
    2) Place this code at the start of the Char script's DoRigidbodyMovement function.
  • Thanks again! 
    I was on the correct path, as I had basically done this and more. I changed my MeshCollider to only return the targetPos. I had it as giving a start point also. Removing the rigidbody got my character moving correctly. However I needed my rigidbody, so I also had to stop the call to Turn() in Char because it uses only x z tangent comparisons.

    Working well now with Pathfinding Method : Custom, and no using the layers to target NavMesh. Thank you!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.