Skip to content

Commit

Permalink
Added a hand-to-controller offset and a speed multiplier to fix body …
Browse files Browse the repository at this point in the history
…lag.
  • Loading branch information
kvoeten committed Mar 29, 2021
1 parent 0b0a32d commit f79ebe6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
Binary file modified Content/Character/Mesh/UE4_Mannequin_Skeleton.uasset
Binary file not shown.
16 changes: 9 additions & 7 deletions Source/UnrealBody/Private/Animation/IKCharacterAnimInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ void UIKCharacterAnimInstance::UpdateFootIK()
FCollisionQueryParams Params;
Params.AddIgnoredActor(Character);

// Debug Draw
const FName TraceTag("FeetTraces");
World->DebugDrawTraceTag = TraceTag;
Params.TraceTag = TraceTag;

// Trace both feet and set result in AnimGraph
TraceFoot(LeftFoot, &FootIKValues.LeftFootLocation,
&FootIKValues.LeftFootRotation, World, &Params);
Expand Down Expand Up @@ -141,9 +136,16 @@ void UIKCharacterAnimInstance::UpdateHandValues()
{
USkeletalMeshComponent* OwnerComp = GetOwningComponent();

// Get offsets
FTransform LeftOffset = OwnerComp->GetSocketTransform("hand_lSocket", ERelativeTransformSpace::RTS_ParentBoneSpace);
FTransform RightOffset = OwnerComp->GetSocketTransform("hand_rSocket", ERelativeTransformSpace::RTS_ParentBoneSpace);

// Fix left offset
LeftOffset.ScaleTranslation(-1);

// Get controller transform * offset
ArmIKValues.LeftTargetTransform = this->BodyComponent->LeftController->GetComponentTransform();
ArmIKValues.RightTargetTransform = this->BodyComponent->RightController->GetComponentTransform();
ArmIKValues.LeftTargetTransform = this->BodyComponent->LeftController->GetComponentTransform() * LeftOffset;
ArmIKValues.RightTargetTransform = this->BodyComponent->RightController->GetComponentTransform() * RightOffset;
}

void UIKCharacterAnimInstance::UpdateMovementValues()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void UIKBodyComponent::TickBodyMovement(float DeltaTime)
else
{
// Tick towards location based on movement speed
this->BodyCurrentLocation = UKismetMathLibrary::VInterpTo(this->BodyCurrentLocation, this->BodyTargetLocation, DeltaTime, MovementSpeed);
this->BodyCurrentLocation = UKismetMathLibrary::VInterpTo(this->BodyCurrentLocation, this->BodyTargetLocation, DeltaTime, MovementSpeed * this->MovementSpeedMultiplier);
this->Body->SetWorldLocation(BodyCurrentLocation);
}

Expand Down
10 changes: 9 additions & 1 deletion Source/UnrealBody/Public/CharacterComponents/IKBodyComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,15 @@ class UNREALBODY_API UIKBodyComponent : public UActorComponent
UCameraComponent* Camera = nullptr;

/*
Movement Values, replicated (server changes are sent to clients)
* Non-Replicated Setting variables
*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Settings")
float MovementSpeedMultiplier = 1.0f
UMETA(Tooltip = "Increase or decrease the speed of the character during movement. Use this to avoid the character lagging behind over longer distances.");


/*
* Movement Values, replicated (server changes are sent to clients)
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Replicated, Category = "IKBody")
float MovementThreshold = 60.0f
Expand Down
2 changes: 1 addition & 1 deletion UnrealBody.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "1.1",
"VersionName": "1.0.2",
"FriendlyName": "Unreal Body Plugin",
"Description": "Standalone plugin that provides an IK body, with finger collision, animated by 3 tracking points.",
"Category": "VR",
Expand Down

0 comments on commit f79ebe6

Please sign in to comment.