Hello, I recently started development on a VR climbing game. However, I have a problem where when I try to grab a climbable object with both hands, they slip and I fall. It does work for only have hand though. Any ideas how to fix this?
using UnityEngine;
using System.Collections;
public class GripManager : MonoBehaviour
{
public Rigidbody Body;
public Pull left;
public Pull Right;
// Update is called once per frame
void Start()
{
Body.constraints = RigidbodyConstraints.FreezePositionY;
}
void FixedUpdate()
{
var devicer = SteamVR_Controller.Input((int)Right.controller.index);
var devicel = SteamVR_Controller.Input((int)left.controller.index);
bool isGripped = left.cangrip || Right.cangrip;
if (isGripped)
{
if (left.cangrip && devicel.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
{
Body.useGravity = false;
Body.isKinematic = true;
Body.transform.position += (left.prevpos - left.transform.localPosition);
Body.constraints = ~RigidbodyConstraints.FreezePositionY;
}
else if (left.cangrip && devicel.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))
{
Body.useGravity = true;
Body.isKinematic = false;
Body.velocity = (left.prevpos - left.transform.localPosition) / Time.deltaTime;
}
if (Right.cangrip && devicel.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
{
Body.useGravity = false;
Body.isKinematic = true;
Body.transform.position += (Right.prevpos - Right.transform.localPosition);
Body.constraints = ~RigidbodyConstraints.FreezePositionY;
}
else if (Right.cangrip && devicel.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))
{
Body.useGravity = true;
Body.isKinematic = false;
Body.velocity = (Right.prevpos - Right.transform.localPosition) / Time.deltaTime;
}
}
else
{
Body.useGravity = true;
Body.isKinematic = false;
}
left.prevpos = left.controller.transform.localPosition;
Right.prevpos = Right.controller.transform.localPosition;
}
}
The “Pull” script it is calling in the beginning is just a reference for all the game objects and stuff. I appreciate all the help! Thanks!