Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SDK question(s)
#18
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;
         }
      }
   }
}
Reply


Messages In This Thread
SDK question(s) - by Stain2319 - 02-29-2020, 12:28 AM
RE: SDK question(s) - by emalafeew - 02-29-2020, 12:33 PM
RE: SDK question(s) - by emalafeew - 02-29-2020, 01:56 PM
RE: SDK question(s) - by emalafeew - 02-29-2020, 02:11 PM
RE: SDK question(s) - by Stain2319 - 02-29-2020, 03:49 PM
RE: SDK question(s) - by emalafeew - 02-29-2020, 03:57 PM
RE: SDK question(s) - by Stain2319 - 02-29-2020, 04:17 PM
RE: SDK question(s) - by Stain2319 - 02-29-2020, 11:39 PM
RE: SDK question(s) - by emalafeew - 03-01-2020, 08:38 AM
RE: SDK question(s) - by Stain2319 - 03-03-2020, 04:14 PM
RE: SDK question(s) - by Stain2319 - 03-03-2020, 07:00 PM
RE: SDK question(s) - by Stain2319 - 03-03-2020, 11:09 PM
RE: SDK question(s) - by Stain2319 - 03-05-2020, 03:10 PM
RE: SDK question(s) - by Stain2319 - 03-04-2020, 03:00 AM
RE: SDK question(s) - by Stain2319 - 03-09-2020, 10:40 PM
RE: SDK question(s) - by emalafeew - 03-10-2020, 12:02 PM
RE: SDK question(s) - by Stain2319 - 03-10-2020, 12:46 PM
RE: SDK question(s) - by emalafeew - 03-10-2020, 02:32 PM
RE: SDK question(s) - by Stain2319 - 03-10-2020, 02:54 PM
RE: SDK question(s) - by emalafeew - 03-10-2020, 03:54 PM
RE: SDK question(s) - by Stain2319 - 03-10-2020, 04:59 PM
RE: SDK question(s) - by emalafeew - 03-10-2020, 07:53 PM
RE: SDK question(s) - by Stain2319 - 03-11-2020, 01:13 AM
RE: SDK question(s) - by Stain2319 - 03-11-2020, 10:20 PM
RE: SDK question(s) - by emalafeew - 03-12-2020, 04:32 PM
RE: SDK question(s) - by Stain2319 - 03-12-2020, 05:57 PM
RE: SDK question(s) - by Stain2319 - 03-12-2020, 07:34 PM
RE: SDK question(s) - by Stain2319 - 03-12-2020, 11:07 PM
RE: SDK question(s) - by Stain2319 - 03-13-2020, 03:02 PM
RE: SDK question(s) - by emalafeew - 03-13-2020, 03:25 PM
RE: SDK question(s) - by Stain2319 - 03-18-2020, 02:53 AM
RE: SDK question(s) - by emalafeew - 03-19-2020, 02:05 PM
RE: SDK question(s) - by Stain2319 - 03-19-2020, 03:17 PM
RE: SDK question(s) - by Stain2319 - 03-22-2020, 02:35 AM
RE: SDK question(s) - by Stain2319 - 03-22-2020, 03:22 PM
RE: SDK question(s) - by emalafeew - 03-22-2020, 03:45 PM
RE: SDK question(s) - by Stain2319 - 03-22-2020, 03:47 PM
RE: SDK question(s) - by Stain2319 - 03-26-2020, 12:16 PM
RE: SDK question(s) - by emalafeew - 03-26-2020, 01:52 PM
RE: SDK question(s) - by emalafeew - 03-26-2020, 02:18 PM
RE: SDK question(s) - by Stain2319 - 03-26-2020, 03:07 PM
RE: SDK question(s) - by Stain2319 - 03-31-2020, 06:46 PM
RE: SDK question(s) - by emalafeew - 03-31-2020, 07:08 PM
RE: SDK question(s) - by Stain2319 - 03-31-2020, 07:41 PM
RE: SDK question(s) - by Stain2319 - 03-31-2020, 08:56 PM
RE: SDK question(s) - by Shon_T - 03-31-2020, 09:20 PM
RE: SDK question(s) - by Stain2319 - 03-31-2020, 10:18 PM
RE: SDK question(s) - by emalafeew - 04-01-2020, 02:58 PM
RE: SDK question(s) - by Snowpelt - 04-02-2020, 12:12 AM
RE: SDK question(s) - by emalafeew - 04-02-2020, 10:30 AM
RE: SDK question(s) - by Shon_T - 04-02-2020, 06:45 PM
RE: SDK question(s) - by Stain2319 - 04-10-2020, 03:46 PM
RE: SDK question(s) - by emalafeew - 04-13-2020, 04:40 PM
RE: SDK question(s) - by Stain2319 - 04-10-2020, 06:09 PM
RE: SDK question(s) - by Stain2319 - 04-14-2020, 02:29 PM

Forum Jump:


Users browsing this thread: 10 Guest(s)