Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
30 changes: 30 additions & 0 deletions Assets/ClimbInteractable.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;

public class ClimbInteractable : XRBaseInteractable
{
protected override void OnSelectEntered(SelectEnterEventArgs args)
{

if (args.interactorObject is XRDirectInteractor)
{
Climber.climbingHand = args.interactorObject.transform.parent.GetComponent<ActionBasedController>();
}

base.OnSelectEntered(args);
}


protected override void OnSelectExited(SelectExitEventArgs args)
{

if (Climber.climbingHand && Climber.climbingHand.name == args.interactorObject.transform.parent.name)
{
Climber.climbingHand = null;
}
base.OnSelectExited(args);
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 100 additions & 0 deletions Assets/Climber.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.XR;
using UnityEngine.XR.Interaction.Toolkit;
public class Climber : MonoBehaviour
{
public CharacterController character;
public static ActionBasedController climbingHand;
private SwingingArmMotion continuousMovement;
private jumpScript jump;

private ActionBasedController previousHand;
private Vector3 previousPos;
private Vector3 currentVelocity;

// Start is called before the first frame update
void Start()
{
continuousMovement = GetComponent<SwingingArmMotion>();
jump = GetComponent<jumpScript>();
}

void Update()
{

if (climbingHand)
{
Debug.Log("climbing hand");
if (previousHand == null)
{
previousHand = climbingHand;
previousPos = climbingHand.positionAction.action.ReadValue<Vector3>();
}
if (climbingHand.name != previousHand.name)
{
previousHand = climbingHand;
previousPos = climbingHand.positionAction.action.ReadValue<Vector3>();
//Debug.Log("DIFFERENT HAND NOW");
}
continuousMovement.enabled = false;
jump.enabled = false;

Climb();
}
else
{
//Debug.Log("not climbing hand");
continuousMovement.enabled = true;
jump.enabled = true;
}
}
void Climb()
{
currentVelocity = (climbingHand.positionAction.action.ReadValue<Vector3>() - previousPos) / Time.deltaTime;
character.Move(transform.rotation * -currentVelocity * Time.deltaTime);

previousPos = climbingHand.positionAction.action.ReadValue<Vector3>();
}
}
/*{
private CharacterController character;
public static Climber Instance;
public XRController climbingHand;
private SwingingArmMotion continuousMovement;
private void Awake()
{
Instance = this;
}

// Start is called before the first frame update
void Start()
{
character = GetComponent<CharacterController>();
continuousMovement = GetComponent<SwingingArmMotion>();

}

// Update is called once per frame
void FixedUpdate()
{
if(climbingHand)
{
Debug.Log("stop movement and climb");
continuousMovement.enabled = false;
Climb();
}
else
{
continuousMovement.enabled = true;
}
}
void Climb()
{
InputDevices.GetDeviceAtXRNode(climbingHand.controllerNode).TryGetFeatureValue(CommonUsages.deviceAngularVelocity, out Vector3 velocity);

PlayerMovement.AddMovement(transform.rotation * -velocity * Time.fixedDeltaTime);
}
}*/

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading