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