Skip to content

Commit

Permalink
fix(Tracking): ensure velocity is not set on kinematic rigidbody
Browse files Browse the repository at this point in the history
Rigidbodies cannot have velocities set on them if they are kinematic
as they are not actually part of the physics simulation when kinematic
so this fix just ensures the kinematic state is checked before trying
to apply a velocity to a rigidbody.
  • Loading branch information
thestonefox committed Mar 13, 2023
1 parent 5d14336 commit c588d73
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected override void DoModify(GameObject source, GameObject target, GameObjec
Vector3 velocityTarget = positionDelta / deltaTime;
Vector3 calculatedVelocity = Vector3.MoveTowards(cachedTargetRigidbody.velocity, velocityTarget, MaxDistanceDelta / deltaTime);

if (calculatedVelocity.sqrMagnitude < VelocityLimit)
if (!cachedTargetRigidbody.isKinematic && calculatedVelocity.sqrMagnitude < VelocityLimit)
{
cachedTargetRigidbody.velocity = calculatedVelocity;
}
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Tracking/Velocity/VelocityApplier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public virtual void ClearTarget()
/// </summary>
public virtual void Apply()
{
if (!this.IsValidState() || Source == null || Target == null)
if (!this.IsValidState() || Source == null || Target == null || Target.isKinematic)
{
return;
}
Expand Down

0 comments on commit c588d73

Please sign in to comment.