Player resets to previous position or 0,0,0 only sometimes
Making a climbing mechanic using Vive controllers, narrowed it down, I feel like it's a simple transform script. However, occasionally the player will reset back to a previous spot/hold, or at runtime it will sometimes reset the player to 0, 0, 0 on first grip (and occasionally when playing as well). 70-80% of the time it works fine. Seems exacerbated by high speeds but happens without.
Here is the relevant code. Omitted all rigidbody and collider stuff. I really feel like it's gotta be something obvious I'm overlooking but I can't find anything about this online.
Each controller has this same script on it, except the other is startPlayerLeft and startPosLeft.
public void OnTriggerStay(Collider other)
{
if (triggerButtonDown)
{
startPosRight = trackedObj.transform.localPosition;
startPlayerRight = PlayerBody.transform.localPosition;
}
if (triggerButtonPressed)
{
PlayerBody.transform.localPosition = startPlayerRight + (startPosRight + -trackedObj.transform.localPosition);
}
}
I also have this now placed in FixedUpdate with a bool call in OnTriggerStay. Still exactly the same issue. I don't have any PlayerBody or trackedObj transforms anywhere else in the script.
I think your best bet is to debug the code. print each step. So inside triggerButtonDown add a print, and inside triggerButtonPressed add another one.
Your answer
![](https://koobas.hobune.stream/wayback/20220612084347im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Scene Reset on HTC Vive Idle? 0 Answers
Keep the distance of one object relative to another while changing its size 0 Answers
Snapping Objects 0 Answers