Advertisement
salahzar

FlyingObject.cs

Jun 16th, 2021 (edited)
443
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. using UdonSharp;
  2. using UnityEngine;
  3. using VRC.SDKBase;
  4. using VRC.Udon;
  5.  
  6. public class FlyingObject : UdonSharpBehaviour
  7. {
  8.     private VRCPlayerApi playerLocal;
  9.     private bool isActive;
  10.     public float maxvelocity = 3;
  11.  
  12.     void Start()
  13.     {
  14.         playerLocal = Networking.LocalPlayer;
  15.     }
  16.  
  17.     override public void OnPickupUseDown()
  18.     {
  19.         Debug.Log("set active true");
  20.         isActive = true;
  21.     }
  22.     override public void OnPickupUseUp()
  23.     {
  24.         Debug.Log("set active false");
  25.         isActive = false;
  26.     }
  27.  
  28.     private void FixedUpdate()
  29.     {
  30.         if (isActive)
  31.         {
  32.             Vector3 newvel = Vector3.ClampMagnitude(playerLocal.GetVelocity() + transform.forward, maxvelocity);
  33.             Debug.Log("setting velocity to " + newvel);
  34.             playerLocal.SetVelocity(newvel);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement