[RELEASED] Easy Character Movement 2

Is there anyway to get a proper dot product of the camera forward and requested movement by either projecting, scaling, removing or clamping down the camera’s forward so if your looking up or down it doesnt effect the resulting dot product? ive tried just removing the y axis only before realizing its not a vector3 position but a vector3 direction. what would be the best way to go about this that would result in the least amount error? (i am trying to replicate source-like air strafing and comparing other dot products and vector3 directions/forces to later scale them dynamically during the velocity calculation. im also curious if i can make a protected virtual float or vector3 to route the calculations to rather than making my code messier with more if/else statements)

Hi,

is there a way to adjust the movement speed based on joystick input? So if i press only slightly the character moves slow (walks) the more i press the joystick to the side the faster the character goes until max. Speed. Actually my character moves immediately fast. Slower Acceleration is not possible as this has negative impact on responsiveness.

Thanks in Adsvance

Hi @e199

ECM2 uses its origin at the bottom of the capsule, so it’s recommended to set your animation origin accordingly. In this case, select ‘Based Upon’ Feet to ensure proper alignment.

Please refer to the following image from the included ‘HumanoidMidAirRight’ Animation Clip.

Hi @icrazedupgamingyt ,

Yes, you can project both your movement direction and your camera forward vector onto a plane defined by the up vector. For example, you can do something like this:

var A = Vector3.ProjectOnPlane(cameraForward, Vector3.up).normalized;
var B = Vector3.ProjectOnPlane(movementDirection, Vector3.up).normalized;

var dot = Vector3.Dot(A, B);

For the directional part, you can implement something similar to the one used here

Hi @WengstiDev,

This is already implemented. Just make sure your inputs are not normalized so that they are actual analog values in the 0-1 range, rather than digital 0 or 1.

1 Like

Hello!

Am I missing it or was the spline movement example (using cinemachine paths) removed?
Is there any way that could be included again?

There are splines in one of the 2D samples, take a look there.

1 Like

Hi,

The ECM2 Cinemachine example hasn’t been ported to the latest version yet. I will update it and include it in the next release.

In the meantime, if you’re interested, feel free to contact me through the support email (please include your invoice number), and I can provide you with the example from the previous version.

Sounds good thanks!

1 Like

hey i tried converting my character movement code from a monobehavior to a networkbehavior for fishnet similar to how it was in the example and it seemed to completely break the script do you know what could be causing this?

This could be because the Fishnet example is limited to just using the CharacterMovement component without the Character class. If your code is character-based, it won’t work directly with Fishnet in the same way.

Hey Krull, would you know the best way to add a rotation like a recoil effect while still keeping the pitch clamp?

I’ve tried doing this

(...)
 cameraTarget.transform.localRotation = Quaternion.Euler(_cameraPitch + currentRecoil.y, 0.0f, 0.0f);
}
public void ApplyRecoil()
{
    float recoilY = Random.Range(-0.5f, -5f);
    //float recoilX = Random.Range(-60f, 60f);
    /argetRecoil += new Vector3(0, recoilY, 0);
    currentRecoil = Vector3.Lerp(currentRecoil, targetRecoil, Time.deltaTime * .9f);
}

But it seems to break the clamp, meaning if I kept looking up the camera would go over the character.
Just want to quickly rotate the camera upwards for a camera recoil effect. thank you

Hi @EpicMcDude ,

You can use the AddControlPitchInput function to apply the pitch, as it already includes clamping parameters. That said, it is essentially just a shorthand for clamping the provided pitch value. In your case, it would look like this:

finalPitch = Mathf.Clamp(_cameraPitch + CurrentRecoil.y, minPitch, maxPitch);
cameraTarget.transform.localRotation = Quaternion.Euler(finalPitch, 0.0f, 0.0f);