Beispiel #1
0
    public static TSVector2 Lerp(TSVector2 value1, TSVector2 value2, FP amount)
    {
        amount = TSMath.Clamp(amount, 0, 1);

        return(new TSVector2(
                   TSMath.Lerp(value1.x, value2.x, amount),
                   TSMath.Lerp(value1.y, value2.y, amount)));
    }
Beispiel #2
0
    public void FixedUpdate()
    {
        this.wheelAngle = TSMath.Lerp(this.wheelAngle, this.steerAngle, Time.fixedDeltaTime * this.steerTime);
        if (TSPhysics.Raycast(transform.position.ToTSVector(), (-transform.up).ToTSVector(), out TSRaycastHit hit, maxLength + wheelRadius))
        {
            lastLength     = springLength;
            springLength   = hit.distance.AsFloat() - wheelRadius;
            springLength   = TSMath.Clamp(springLength, minLength, maxLength).AsFloat();
            springVelocity = (lastLength - springLength) / Time.fixedDeltaTime;
            springForce    = springStiffness * (restLength - springLength);
            damperForce    = damperStiffness * springVelocity;

            suspensionForce = (springForce + damperForce) * transform.up.ToTSVector();

            this.wheelVelocityLS = this.tsTransform.InverseTransformDirection(this.trb.GetPointVelocity(hit.point));

            this.Fx = Input.GetAxis("Vertical") * springForce * speed;
            this.Fy = wheelVelocityLS.x * springForce;

            this.trb.AddForceAtPosition(suspensionForce + (Fx * transform.forward.ToTSVector()) + (Fy * (transform.right.ToTSVector() * -1)), hit.point);
        }
    }
 void Update()
 {
     if (Selection.activeGameObject != this.gameObject)
     {
         if (this.doSmoothing)
         {
             float t = (Time.time - Time.fixedTime) / Time.deltaTime;
             transform.position = TSVector2.Lerp(this.lastPosition, this.nextPosition, (FP)t).ToVector2();
             float angle = (float)TSMath.Lerp(this.lastAngle, this.nextAngle, t);
             transform.rotation = Quaternion.Euler(0.0f, 0.0f, Mathf.Rad2Deg * angle);
         }
         else
         {
             transform.position = this.body.Position.ToVector2();
             transform.rotation = Quaternion.Euler(0.0f, 0.0f, (float)(Mathf.Rad2Deg * this.body.Angle));
         }
     }
     else
     {
         this.body.Set(
             this.transform.position.ToTSVector2(),
             Mathf.Deg2Rad * this.transform.rotation.eulerAngles.z);
     }
 }
Beispiel #4
0
 public static void LerpUnclamped(ref TSVector2 value1, ref TSVector2 value2, FP amount, out TSVector2 result)
 {
     result = new TSVector2(
         TSMath.Lerp(value1.x, value2.x, amount),
         TSMath.Lerp(value1.y, value2.y, amount));
 }
Beispiel #5
0
 public static TSVector2 LerpUnclamped(TSVector2 value1, TSVector2 value2, FP amount)
 {
     return(new TSVector2(
                TSMath.Lerp(value1.x, value2.x, amount),
                TSMath.Lerp(value1.y, value2.y, amount)));
 }