Created
August 8, 2022 10:43
-
-
Save DraconInteractive/412484fea7d1a8f2f695ef75f7bd695e to your computer and use it in GitHub Desktop.
Basic Uxr Climbing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections; | |
using System.Collections.Generic; | |
using UltimateXR.Avatar; | |
using UltimateXR.Core; | |
using UltimateXR.Core.Components.Composite; | |
using UltimateXR.Manipulation; | |
using UnityEngine; | |
public class ClimbingHold : UxrGrabbableObjectComponent<ClimbingHold> | |
{ | |
private UxrAvatar avatar; | |
private UxrGrabber grabber; | |
public float multiplier; | |
public bool grabbed; | |
private Vector3 lastPos; | |
protected override void Start() | |
{ | |
base.Start(); | |
GrabbableObject.IsLockedInPlace = true; | |
grabbed = false; | |
} | |
private void Update() | |
{ | |
if (grabbed) | |
{ | |
Vector3 velocity = grabber.UnprocessedGrabberPosition - lastPos; | |
UxrManager.Instance.TranslateAvatar(avatar, -velocity * multiplier); | |
lastPos = grabber.UnprocessedGrabberPosition; | |
} | |
} | |
protected override void OnObjectGrabbed(UxrManipulationEventArgs e) | |
{ | |
base.OnObjectGrabbed(e); | |
avatar = e.Grabber.Avatar; | |
grabber = e.Grabber; | |
grabbed = true; | |
lastPos = grabber.UnprocessedGrabberPosition; | |
} | |
protected override void OnObjectReleased(UxrManipulationEventArgs e) | |
{ | |
base.OnObjectReleased(e); | |
if (e.Grabber == grabber) | |
{ | |
grabbed = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment