SmoothDamp with Vector3

First, my code:

            newPosition = gravity.ActualGravity(_movementVector, actionState.isAi); // The original Movement Vector I was using in transform.Translate

            float newX = Mathf.SmoothDamp(parentObjectTransform.position.x, newPosition.x, ref xVelocity, smoothTime); // All the ref variables are set to 0
            float newY = Mathf.SmoothDamp(parentObjectTransform.position.y, newPosition.y, ref yVelocity, smoothTime);
            float newZ = Mathf.SmoothDamp(parentObjectTransform.position.z, newPosition.z, ref zVelocity, smoothTime);
            Vector3 newMovementVector = new Vector3(newX, newY, newZ);

            parentObjectTransform.Translate(newMovementVector);

This method is run when the unit is grounded.

The second he lands he gets dragged through the terrain.

I believe that I followed this well, but for some reason it’s not working.

Lastly, gravity.ActualGravity() applies movement speed to the vector before translating the GameObject.

  • The purpose of this is to fix a Vector3 Translation so that it doesn’t bounce as much.

Thanks for any help provided.

Check the reference for Vector3.SmoothDamp.

This should work fine (of course, add the ‘velocity’ variable):

Vector3 newMovementVector = Vector3.SmoothDamp(newMovementVector, parentObjectTransform.position, ref velocity, smoothTime * Time.deltaTime);

EDIT:
I would suggest you create a new GameObject which you will be moving, then use SmoothDamp to bring the actual object you want to move on the right spot.