Hello all,
I hope I’m posting this in the right area.
in short:
I want to have the player climb up a ladder using the rungs of the ladder. Can any one give me a hand or point me in the right direction?
in long:
the event chain I invasion is as follows:
1)The player will move his controller’s spherical-collider into the collider of the rung.
2) the player clicks and hold a button(tag check).
3)the player is attached to the rung, the player’s hand/controller will stay fixed to the rung until release(no longer free to float around).
4)as he moves his controller up/down his body rig will move in the opposite direct(for ascent/decent).
5) player releases the button and is detached from the rung.
I am pretty new to Unity and VR, but I’ve been looking at tutorials and it doesn’t seem like it should be too difficult. A force based movement seems to be the best way to do it. so that environmental affects can pull/blow you off.
ive been trying to addapt one of the Vive minuet tutorials (
) to do this. just adding a grabbed bool and then trying to figure out how to get the logic right.
in the following code it seems to be line#47 where i try to move the player based on the controller movement that seems to be wrong.
for some reason when i move click the button, the controller jumps to the world origin. and also the player camera wont move with the controller movement.
ps.
ive edited this code to cut of some artifacts from previous attempts.
public class ClimbLadder01: MonoBehaviour
{
private Valve.VR.EVRButtonId triggerButton =
Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger;
public SteamVR_Controller.Device controller { get { return
SteamVR_Controller.Input((int)trackedObj.index); } }
public SteamVR_TrackedObject trackedObj;
public Transform eyeTransform; //the [CameraRig] from the valve SDK
public GameObject obj;
public bool grabbed;
public Rigidbody rig;
void Start()
{
trackedObj = GetComponent<SteamVR_TrackedObject>();
fJoint = GetComponent<FixedJoint>();
}
void Update()
{
if (controller.GetPressDown(triggerButton))
{
Debug.Log("trigger down");
PickUpObj();
}
if (controller.GetPressUp(triggerButton))
{
Debug.Log("trigger up");
DropObj();
}
private void FixedUpdate()
{
if (grabbed)//well move the camera based on the controllered movment.
{
eyeTransform.position = eyeTransform.position - this.gameObject.transform.position;
}
void OnTriggerStay(Collider other)//built in event from unity
{
if (other.CompareTag("PickUpable"))
{
obj = other.gameObject;
//Debug.Log("enter");
}
}
void PickUpObj()
{
if (obj != null)
{
fJoint.connectedBody = obj.GetComponent<Rigidbody>();
throwing = false;
rig = null;
grabbed = true;
}
else
{
fJoint.connectedBody = null;
throwing = false;
}
}
void DropObj()
{
if (obj != null)
{
rig = fJoint.connectedBody;
fJoint.connectedBody = null;
grabbed = false;
}
}
}