I’m looking to extend/change the swimming mechanics a bit and hope I can ask for some advice on it so I can do it properly.
A question on the FirstPersonSwim example:
If I change the “jump” strength so that the character never leaves the water volume fully it will fall to the ground if immersion depth is less than 0.65. Is this intended by design?
Because maybe I don’t quite understand how it is supposed to work conceptually.
Anyway, my thought is to use CalcImmersionDepth to change both walk and swim behaviour depending on immersion depth and use the pivot Point as reference instead of center.
For example, small immersion only some fx, some immersion will restrict run/sprint and more immersion to enter swim mode (where I intend to have one Surface swim sub mode and a Dive mode that is the same as implemented in ECM2 already).
So if you have some clarification on the existing swim example behaviour mentioned above and also if my own thinking on CalcImmersionDepth is a decent way to implement thing or if there’s another way of doing it that perhaps is preferred?
Immersion Depth indicates how submerged the capsule is within the water volume. It is measured from its base to its top, providing a ratio between 0 and 1.
This immersion depth, along with your gravity settings, is used to simulate buoyancy, which is also affected by the water volume’s friction.
All of this is handled in the SwimmingMovementMode, which, like most components in the package, can be extended or replaced as needed for your game.
If you want to prevent the character from reaching the bottom, you can increase the buoyancy value and/or adjust the water volume’s friction.
But there might be a bug or unwanted behaviour though because the character goes into falling mode and then into walking (reaching the bottom) while still being inside the physics volume.
Unlike regular triggers, a character is considered inside (or outside) a water volume by its center. In your case, please make sure the water volume fully covers the bottom; otherwise, the character will correctly exit it.
You can observe this behavior in the First Person Swim example.
I’ve been trying the AddForce and LaunchCharacter on a NavMeshCharacter to add an impulse towards a direction but I’m doing something wrong as they stay in the same place.
I’ve tried using Rigidbody.MovePosition but the physics collision doesn’t work automatically since the rigibody is kinematic so the NavMeshCharacter goes through walls when very close to them.
What would be the best way to add an impulse on a NavMeshCharacter towards a direction while respecting physics?
In ECM2, an “agent” character is essentially a regular character, with the difference that its movement is controlled by the agent. All standard character features work the same way. The only real distinction is that its SetMovementDirection is determined by the NavMeshAgent’s desired velocity instead of player input.
I recommend testing the included AI Navigation example (ECM2\Walkthrough\8 - AI Navigation) by adding a simple impulse. For example:
public class ClickToMove : MonoBehaviour
{
public Vector3 force;
public Camera mainCamera;
public Character character;
public LayerMask groundMask;
private NavMeshCharacter _navMeshCharacter;
private void Awake()
{
_navMeshCharacter = character.GetComponent<NavMeshCharacter>();
}
private void Update()
{
if (Input.GetButtonDown("Jump"))
{
character.AddForce(force, ForceMode.Impulse);
}
if (Input.GetMouseButton(0))
{
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit hitResult, Mathf.Infinity, groundMask))
{
_navMeshCharacter.MoveToDestination(hitResult.point);
}
}
}
}
It’s important to note that, like regular characters, agents have a ground constraint feature. To allow a character to leave the ground, you must explicitly call PauseGroundConstraint(0.1f);, otherwise, it will remain constrained to the ground.
is there a way to push NavMeshCharacters out of the way of the Player?
Additionally, if you want characters to push others, make sure to enable both “Enable Physics Interaction” and “Apply Push Force To Characters.” When enabled, characters will be able to push others based on their mass—heavier characters will have an easier time pushing lighter ones, and vice versa.
Thank you for explaining, I got a little bit confused by the component names between Nav Mesh Character, Character Movement and Character, with the Nav Mesh Character using composition instead of inheritance (concepts I just learned by reading your documentation!) wrongly thought I only needed one ‘Character’ component.
Hello! It may be somewhere in this huge string of comments, but I didn’t see it.
I am trying to use this with a Cinemachine free look camera. The camera hooks up no problem, but the issue comes when the camera rotates to look at the character object and what is up/down as/left/right seems to stay stagnant. Like up becomes down and such. How can I make sure as the character rotates, and the camera rotates, that the direction I am trying to move is consistent?
Yes, a little technical concepts, however the best part of the NavMeshCharacter component using composition is it can be re-utilizable without further modification.
There are working Cinemachine examples included in the package—featuring both third-person and first-person character setups—that demonstrate how to properly integrate Cinemachine with character movement.
These examples should help you see how the movement direction can be aligned with the camera’s rotation to ensure consistency (ie: movement relative to camera’s view direction). Take a look at them, and feel free to ask if you have any more questions!
Hey,
I’m wondering how I can make a custom movement mode where the player can’t move. For example whenever the player opens their inventory they become unable to move but they are still affected by physics, environment, etc. One solution can be to just to disable input but this is something I’d like to avoid if possible. Thanks!
While a custom movement mode could work, you can also use the Character Pause method. When paused, the character becomes completely unresponsive—no movement, no rotation, no collisions, and no interactions of any kind.
public void Pause(bool pause, bool clearState = true)
It has come to my attention that I was still using version 1… the asset had no been added to my library as I thought. Thanks for the timely response! version 2 has what I need great job!