public override Vector3 getVelocity() { float totalWeight = getWeightedMovements().Select(x => x.getWeight()).Aggregate((x, y) => x + y); if (totalWeight == 0) { return(Vector3.zero); } Vector3 totalVelocity = Vector3.zero; foreach (_WeightedMovement weightedMovement in getWeightedMovements()) { _MovementAlgorithm movement = weightedMovement.getMovement(); if (movement is _KinematicMovement) { totalVelocity += movement.getVelocity() * weightedMovement.getWeight(); } else if (movement is _DynamicMovement) { ((_DynamicMovement)movement).update(); totalVelocity += movement.getVelocity() * weightedMovement.getWeight(); } } totalVelocity /= totalWeight; return(totalVelocity); }
void FixedUpdate() { if (movementAlgorithm is _KinematicMovement) { Vector3 instantaneousVelocity = movementAlgorithm.getVelocity(); Vector3 newVelocity = Vector3.Lerp(rigidbody.velocity, instantaneousVelocity, interpolationAmount * Time.deltaTime); newVelocity.Scale(getDimensionLocks()); rigidbody.velocity = newVelocity; rigidbody.rotation = Quaternion.FromToRotation(Vector3.right, newVelocity); Debug.Log(newVelocity); } else if (movementAlgorithm is _DynamicMovement) { ((_DynamicMovement)movementAlgorithm).update(); Vector3 newVelocity = movementAlgorithm.getVelocity(); newVelocity.Scale(getDimensionLocks()); rigidbody.velocity = newVelocity; rigidbody.rotation = Quaternion.FromToRotation(Vector3.right, newVelocity); } else if (movementAlgorithm is _CompoundMovement) { Vector3 newVelocity = movementAlgorithm.getVelocity(); newVelocity.Scale(getDimensionLocks()); rigidbody.velocity = newVelocity; //rigidbody.rotation = Quaternion.FromToRotation(Vector3.right, newVelocity); } }