SDK question(s) - Printable Version

+- (https://forums.vzfit.com)
+-- Forum: VZfit Forum (https://forums.vzfit.com/forumdisplay.php?fid=5)
+--- Forum: General Discussion (https://forums.vzfit.com/forumdisplay.php?fid=6)
+--- Thread: SDK question(s) (/showthread.php?tid=184)

Pages: 1 2 3 4 5 6


RE: SDK question(s) - Stain2319 - 03-03-2020

Would you be willing to share the helicopter code? - specifically I am interested in leaning back to climb and forward to dive when the rigidbody is not affected by gravity. I get the general idea of looking at HeadBend but would be grateful to see a code example of how you are implementing it in River Run, if you don't mind.


RE: SDK question(s) - Stain2319 - 03-03-2020

Oh and while I'm asking... Smile The info for the Le Tour/Cali Rally cycle would also be helpful for me in terms of how you are detecting the head movement to trigger a wheelie animation. Thanks again!


RE: SDK question(s) - Stain2319 - 03-04-2020

One more thing (sorry - been playing with this all day....)

Using the built-in Unity test scene from the SDK, and the normal VZPlayer object, which I click 'Play' in Unity, it works fine and tell me to hit Enter to play without the bike.

So now I created a scene of my own, added an animated avatar I got from the asset store, added the VZplayer script and the VZController prefab, a rigidbody etc - and when I go to click 'Play' it says PRESS L + R TO RECENTER and I can't get around it... any thoughts?

I do not have the bluetooth dongle plugged in so the bike is definitely not connected to the PC I'm using Unity on...

(03-04-2020, 03:00 AM)Stain2319 Wrote: One more thing (sorry - been playing with this all day....)  

Using the built-in Unity test scene from the SDK, and the normal VZPlayer object, which I click 'Play' in Unity, it works fine and tell me to hit Enter to play without the bike.

So now I created a scene of my own,  added an animated avatar I got from the asset store, added the VZplayer script and the VZController prefab, a rigidbody etc - and when I go to click 'Play' it says PRESS L + R TO RECENTER and I can't get around it... any thoughts?

I do not have the bluetooth dongle plugged in so the bike is definitely not connected to the PC I'm using Unity on...

OK I figured this out - I forgot to set the VZPlayer prefab body to VZController.


RE: SDK question(s) - Stain2319 - 03-05-2020

(03-03-2020, 11:09 PM)Stain2319 Wrote: Oh and while I'm asking... Smile The info for the Le Tour/Cali Rally cycle would also be helpful for me in terms of how you are detecting the head movement to trigger a wheelie animation. Thanks again!

So I've pretty much managed to figure out the rest but this question still eludes me.


RE: SDK question(s) - Stain2319 - 03-09-2020

Bump!


RE: SDK question(s) - emalafeew - 03-10-2020

Sorry so you are past the L+R issue? Sorry that’s old bike nomenclature, I believe you just hit the A button on VZ thumb controller.

Regarding Le Tour wheelies I believe our code looks for two things: an average pedaling speed above a theshold, and an upward change in head angle more than X degrees in Y seconds. I can lookup those thresholds for you


RE: SDK question(s) - Stain2319 - 03-10-2020

Yeah, I got past that issue (I actually do have the original bike) and have been heading down a deep dark rabbit hole of Unity development! Smile

I would appreciate any code examples from your avatars you can share, but the code for the wheelie would be most helpful to me.

Thanks again! I'll be sharing some videos of my creations later on...


RE: SDK question(s) - emalafeew - 03-10-2020

This is the relevent portion of our cyclist code. Things I didn't mention before are how we raise VZPlayer's NeckHeight rather than try to change the origin of the bike model, and also how set down a wheelie based on speed or time.

Code:
public class VZAngleTracker
{
   public void AddAngle(float speed)
   {
      mSamples[mIndex++] = speed;
      mIndex = mIndex % kNumSamples;
   }

   public float GetPreviousAngle(int frames)
   {
      int index = mIndex - frames;
      while (index < 0)
         index += kNumSamples;

      return mSamples[index];
   }

   static int kNumSamples = 45;
   float[] mSamples = new float[kNumSamples];
   int mIndex = 0;
}


public VZCycle : VZPlayer
{
   VZAngleTracker mLookUpTracker = new VZAngleTracker();
   float mOriginalNeckHeight;
   float mOriginalMaxSpeed;
   bool mWheelie = false;
   float mWheelieStartSpeed = 0.0f;
   float mWheelieStartTime = 0.0f;

   void Start()
   {
      mOriginalNeckHeight = NeckHeight;
      mOriginalMaxSpeed = MaxSpeed;
   }

   void Update()
   {
      HandleWheelies();
   }

   void HandleWheelies()
   {
      Vector3 angles = Controller.Head.localEulerAngles;
      float headAngle = angles.x;
      if (headAngle < 180.0f)
         headAngle += 360.0f;

      mLookUpTracker.AddAngle(headAngle);

      const float kNeckVelocity = 0.5f;
      const float kWheelieNeckOffset = 0.3f;

      if (!mWheelie)
      {
         NeckHeight -= Time.deltaTime * kNeckVelocity;
         if (NeckHeight < mOriginalNeckHeight)
            NeckHeight = mOriginalNeckHeight;

         // Check if we accelerated and are going somewhat fast.
         float headDelta = headAngle - mLookUpTracker.GetPreviousAngle(10);
         float lookAngle = angles.y;

         if ((lookAngle > 345.0f || lookAngle < 20.0f) &&
             Speed() > mOriginalMaxSpeed - 3.0f &&
             headDelta < -15.0f &&
             headAngle < 355)
         {
            // Pop a wheelie
            mWheelie = true;
            mWheelieStartSpeed = Speed();
            mWheelieStartTime = Time.time;
         }
      }
      else
      {
         NeckHeight += Time.deltaTime * kNeckVelocity;
         if (NeckHeight > mOriginalNeckHeight + kWheelieNeckOffset)
            NeckHeight = mOriginalNeckHeight + kWheelieNeckOffset;

         // Update our wheelie start speed if we go above it. The bike is usually still accelerating when a wheelie starts,
         // which makes it too easy to hold above mWheelieStartSpeed
         if (Speed() > mWheelieStartSpeed)
            mWheelieStartSpeed = Speed();

         // See if we have diverged from our original wheelie speed by too much or held on too long
         bool done = mWheelieStartSpeed - Speed() > 0.8f ||
                    Time.time - mWheelieStartTime > 8.0f ||
                    (headAngle - mLookUpTracker.GetPreviousSpeed(10) > 15.0f && headAngle > 370);

         if (done)
         {
            // No more wheelie
            mWheelie = false;
         }
      }
   }
}



RE: SDK question(s) - Stain2319 - 03-10-2020

Thanks again! Really appreciate it.


RE: SDK question(s) - emalafeew - 03-10-2020

Sure! I also missed your Heli dive question above. I can get to that after some other support needs, but in a sentence we generate Heli lift like the Pegasus, but to dive we use HeadBend to reduce that lift, increase VZPlayer's MaxVertSpeed to allow it to fall faster, and also increase VZPlayer's SpeedFudge to make it "swoop".