Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vibration to the ship lever when holding it #269

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions Source/Physics/Interactions/ShipLever.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using LCVR.Assets;
using LCVR.Assets;
using LCVR.Networking;
using LCVR.Player;
using System.Collections;
Expand Down Expand Up @@ -34,7 +34,7 @@ public bool OnButtonPress(VRInteractor interactor)

interactor.FingerCurler.ForceFist(true);

lever.StartInteracting(interactor.transform, ShipLever.Actor.Self);
lever.StartInteracting(interactor.transform, ShipLever.Actor.Self, interactor);

return true;
}
Expand All @@ -60,6 +60,8 @@ public class ShipLever : MonoBehaviour
private TriggerDirection shouldTrigger = TriggerDirection.None;
private Actor currentActor;
private Channel channel;
VRInteractor CurrentInteractor;
float LastVibrateRotation;

public bool CanInteract => lever.triggerScript.interactable && currentActor != Actor.Other;

Expand Down Expand Up @@ -98,15 +100,25 @@ private void Update()
shouldTrigger = eulerAngles.x > 290 ? TriggerDirection.DepartShip : TriggerDirection.None;
}

eulerAngles.x = Mathf.Clamp(eulerAngles.x, 270, 310); //Fixes the lever from clipping if you rotate it too much

if (CurrentInteractor != null && Mathf.Abs(LastVibrateRotation - eulerAngles.x) >= 10) //Vibrate the controller if the lever has been rotated too much
{
CurrentInteractor.Vibrate(0.1f, 0.3f);
LastVibrateRotation = eulerAngles.x;
}

transform.eulerAngles = eulerAngles;
}

public void StartInteracting(Transform target, Actor actor)
public void StartInteracting(Transform target, Actor actor, VRInteractor interactor = null)
{
currentActor = actor;
animator.enabled = false;
rotateTo = target;

CurrentInteractor = interactor;


if (actor == Actor.Self)
channel.SendPacket([1]);
}
Expand Down Expand Up @@ -137,6 +149,8 @@ public void StopInteracting()

private IEnumerator PerformLeverAction(bool isLocal)
{
if(CurrentInteractor != null)
CurrentInteractor.Vibrate(.3f, 0.5f);
if (isLocal) lever.LeverAnimation();

yield return new WaitForSeconds(1.67f);
Expand Down