Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SDK question(s)
Been playing with Unity and the SDK today and figured I would start a thread for questions/etc...   

I managed to tweak the built-in Virzoom test scene by putting a texture on the plane, and making it much bigger, and successfully built and loaded the app to my Oculus Quest and rode around a bit.  Pretty neat! 

So I'm going to dive into this a bit more and wanted to get some more info about avatar movement.

You mentioned in the SDK docs:

"We’re happy to share how the avatars in our games all move, just ask on the forum!"

Consider yourselves asked! Smile

I am interested especially in the Pegasus avatar and how to achieve flight/lift...
I’ll post the relevant code and parameters shortly. Each of our avatars subclasses VZPlayer to extend its capability. In the Pegasus case we generate a lift force proportional to pedaling speed when the A button is held down, that is tuned to achieve liftoff at 65 rpm. It also has the concept of a flight ceiling, so the lift force faces an increasing downward ceiling force, which equalizes when Pegasus is at ceiling height pedaling 130 rpm.
This should work with the SDK to duplicate the Pegasus motion.

When attaching the Pegasus model (or other vehicle) to VZPlayer, position so that the seat is at the origin of the VZPlayer. The NeckHeight parameter below presumes your eyes are 0.9 above that origin, so will remain vertical above the seat as the vehicle pitches up and down hills or when flying.

Another thing I left in the code is how the Pegasus dives, when you lean forward and not holding down A button (which in our SDK is Controller.RightButton). Diving is just a matter of letting you fall faster, as opposed to pushing down more.

Note to translate from Controller.InputSpeed to rpm, at the default difficulty of 5, divide by 6.462. That's the distance our initial prototype bike with 27" wheels traveled in one pedal revolution with a gear ratio of 3.

using UnityEngine;

public class VZSimplePegasus : VZPlayer
   /* VZPlayer settings

      NearClipPlane: 0.1
      FarClipPlane: 3000
      DraftSpeed: 0
      DraftFactor: 0
      SpeedFudge: 1
      DownhillFactor: 0.5
      UphillFactor: 1.414
      MaxVertSpeed: 4
      MaxTurn: 0.6 // for Gold Pegasus this becomes 0.7
      MaxSpeed: 12
      LeanFudge: 2.5 // for Gold Pegasus this becomes 3
      LeanIn: 0.5
      LandingHardness: 1.5 // for Gold Pegasus this becomes 2
      LandingRadius: 0.25
      NeckHeight: 0.9 // for pivot point at seat
      AllowRotate: 1
      AllowPitch: 1
      AllowRoll: 0
      AllowDrift: 1 // so she drifts rather than brakes in air when not pedaling
      RotateAtStop: 0
      SlowRotateLimit: 0
      AllowReverse: 0
      ForceReverse: 0
      ResistanceAdjust: 0

   public float LiftSpeed = 7.0f;
   public float MaxHeight = 130.0f; // for Gold Pegasus this becomes 195
   protected override void FixedUpdate()

      // Starts lifting at LiftSpeed
      Vector3 force =;

      if (Controller.RightButton.Down)
         force.y = 9.81f * Controller.InputSpeed / LiftSpeed;

      // Lean forward to dive when coasting
      float bend = Controller.RightButton.Down ? 0 : Mathf.Clamp01(Controller.HeadBend / 0.2f);
      MaxVertSpeed = Mathf.Lerp(4, 7, bend);

      // Lift peters out at MaxHeight
      if (!Colliding() && Altitude() > 0)
         force.y -= 9.81f * Altitude() / MaxHeight;

      // Apply lift force
The game tip you might be able to glean from this code is that the ceiling pressure is proportional to VZPlayer.Altitude(), which is relative to the height of the player when they begin flying. That altitude does not continuously adjust for the ground height under you when flying, so flying difficulty is purely a matter from when you last touched ground. So in Gem Hunt, to be able to fly higher for gems in the air, begin your takeoff from a higher point. This can also help you in Gate Race when taking shortcuts.

I'm new to Unity and mostly only dabble in development so bear with me - I am getting an error with this code.

For now what I am trying to do is essentially just add flying to the default avatar that is in the generic "scene" provided with the SDK.  So I created a FlyingBike.cs script that contains the code you provided and added that to the existing VZPlayer object that represents the bike (and has the VZPlayer script already on it.)

I get the following in Unity:

'VZSimplePegasus.FixedUpdate()': no suitable method found to override

Looking through the default VZPlayer.cs code I do not see a FixedUpdate() method though I do see Update() and UpdateNormal()  (along with UpdateSetup and UpdateNeck) -- should I be using one of those instead of FixedUpdate()?
Ah we’re using an updated sdk internally.

To make it work just take out the words “protected override” from FixedUpdate

Are you planning to publish that updated SDK by chance? Smile

Still getting the same error after this change;  do I need to change this line as well? :

So I think I ran into some issues with subclassing, either because I was using the virzoom bike prefab instead of my own avatar or because I did something wrong....but I was able to just modify the VZPlayer script directly and add this on and got a flying bike. Very cool! Thanks for the info, very helpful so far. I'm not much of a developer (though I do work in tech) but I think I'll be able to cobble together some fun stuff...
Ah yes, I forgot to say you should remove that line as well. Or add it to the base VZPlayer which you did. Good job on getting there!

The unity store has lots of models you can buy for $10-20, which you could hookup in place of our bike model. Animate them and make an environment with scoreable interactions and you’ve got yourself a game!

Our latest internal sdk has that fixed update call for the camera smoothing in our latest Explorer build. So yeah we could release that, but I’ll also be sure to provide sample code that works with our current released sdk in the future.
Thanks so much for the help with this - I really appreciate the fact that you guys are willing to share code!

It has been awhile since I really coded anything but it's like riding a bike (heh), you start to remember the little tricks and algorithms and thankfully there is a ton of stuff online for Unity in terms of scripting help/mods/etc. I managed to implement Jumping with the right trigger on the test bike this morning! Smile

I have a couple ideas bouncing around in my head that I am going to work on.... stay tuned!

Forum Jump:

Users browsing this thread: 2 Guest(s)