Question by
KillerPenguin · Sep 25, 2017 at 02:10 AM ·
physicstransformpositioningjitteringgun movement
Why is this causing weird stutter/jitter?
So I'm working on a project and I got to working on this weapon slide. In a parent class I'm checking to see where the hand is grabbing with:
public Vector3 ClosestPoint(Vector3 startPoint, Vector3 endPoint, Vector3 tPoint)
{
Vector3 startPointTotPointVector = tPoint - startPoint;
Vector3 startPointToEndPointVector = (endPoint - startPoint).normalized;
float d = Vector3.Distance(startPoint, endPoint);
float t = Vector3.Dot(startPointToEndPointVector, startPointTotPointVector);
if (t <= 0)
return startPoint;
if (t >= d)
return endPoint;
Vector3 distanceAlongVector = startPointToEndPointVector * t;
Vector3 closestPoint = startPoint + distanceAlongVector;
return closestPoint;
}
On update I'm checking to see if the slide is held and if it is I get the controllers local transform and set the slides local position with the following code:
switch (this.currentState)
{
case CurrentSlideState.Held:
Vector3 grabHand = this.transform.InverseTransformPoint(attachPointTransform.transform.position);
if (currentPosition != CurrentPosition.Max)
{
this.transform.localPosition = Handgun.ClosestPoint(Handgun.slideMin, Handgun.slideMax, grabHand);
break;
}
break;
}
But the problem is when it is held it tends to jitter like this: https://www.youtube.com/watch?v=_Dm7NMYroCw&feature=youtu.be
Comment
Your answer
Follow this Question
Related Questions
Can you help explain this positioning conundrum to me! 1 Answer
Raycast only occurs on start 2 Answers
OnMouseDrag doesn't wokr. 0 Answers
iscometric grid panning 0 Answers