Skip to content

Instantly share code, notes, and snippets.

@DraconInteractive
Created August 8, 2022 10:43
Show Gist options
  • Save DraconInteractive/412484fea7d1a8f2f695ef75f7bd695e to your computer and use it in GitHub Desktop.
Save DraconInteractive/412484fea7d1a8f2f695ef75f7bd695e to your computer and use it in GitHub Desktop.
Basic Uxr Climbing
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