Esempio n. 1
0
 public void ChangeUp(Vector3 new_up)
 {
     if (LBMath.TruncVector3(new_up.normalized) == LBMath.TruncVector3(right.normalized))
     {
         right   = forward;
         forward = up;
         up      = LBMath.TruncVector3(new_up.normalized);
         return;
     }
     else if (LBMath.TruncVector3(new_up.normalized) == LBMath.TruncVector3(forward))
     {
         forward = right;
         right   = up;
         up      = LBMath.TruncVector3((new_up.normalized));
         return;
     }
     else if (LBMath.TruncVector3(new_up.normalized) == LBMath.TruncVector3(up))
     {
         return;
     }
     else
     {
         up      = LBMath.TruncVector3(new_up.normalized);
         right   = LBMath.TruncVector3(Vector3.ProjectOnPlane(right, new_up).normalized);
         forward = LBMath.TruncVector3((Vector3.ProjectOnPlane(forward, new_up).normalized));
         if (bisortho)
         {
             Vector3.OrthoNormalize(ref up, ref right, ref forward);
         }
     }
 }
Esempio n. 2
0
        protected Vector3 NewWalkSpeed()
        {
            float _res_spd;

            _res_spd = LerpFloat(LBMath.TruncFloat(RBSpeedVectorFlat.magnitude), desired_speed, movement_accel, Time.fixedDeltaTime);
            return(_res_spd * target_rigidbody.transform.forward - FloorNormal * 0.1f * _res_spd);
        }
Esempio n. 3
0
 protected bool bWantsToStand()
 {
     if (bHasFloor && LBMath.TruncFloat(desired_speed) <= MAXIDLETHRESH)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 4
0
 protected bool bIsStanding()
 {
     if (bHasFloor && LBMath.TruncFloat(RBSpeedVectorFlat.magnitude) <= MAXIDLETHRESH)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 5
0
 public float SetPosition(float new_pos, float delta_time, float rate = 0.1f)
 {
     pos = LBMath.LerpFloat(pos, new_pos, rate, delta_time);
     return(pos);
 }
Esempio n. 6
0
 public float SetPosition(float new_pos, float delta_time)
 {
     pos = LBMath.LerpFloat(pos, new_pos, interp_rate, delta_time);
     return(pos);
 }
Esempio n. 7
0
        protected void ProcessWalkState()
        {
            Vector3    new_up, new_forward, floor_fwd;
            Quaternion new_rotation;

            //Quaternion get_new_dir()
            //{
            //    return Quaternion.FromToRotation(Vector3.up, FloorNormal) * Quaternion.LookRotation(Quaternion.Euler(0, desired_direction, 0) * Vector3.forward, Vector3.up);
            //}

            //Vector3 get_new_speed()
            //{
            //    float _res_spd;
            //    _res_spd = LerpFloat(LBMath.TruncFloat(RBSpeedVectorFlat.magnitude), desired_speed, movement_accel, Time.fixedDeltaTime);
            //    return _res_spd * target_rigidbody.transform.forward - FloorNormal * 0.1f * _res_spd;
            //}

            //void walk()
            //{
            //    float res_spd;
            //    res_spd = LerpFloat(LBMath.TruncFloat(RBSpeedVectorFlat.magnitude), desired_speed, movement_accel, Time.fixedDeltaTime);
            //    current_direction = LerpFloat(current_direction, desired_direction, rotation_speed, Time.fixedDeltaTime);
            //    //target_rigidbody.transform.up = FloorNormal;
            //    //target_rigidbody.transform.rotation = target_rigidbody.transform.rotation * Quaternion.Euler(0, current_direction, 0);
            //    new_rotation = Quaternion.FromToRotation(Vector3.up, FloorNormal) * Quaternion.LookRotation(Quaternion.Euler(0, desired_direction, 0) * Vector3.forward, Vector3.up); //Quaternion.Euler(0, desired_direction, 0);
            //    target_rigidbody.transform.rotation = new_rotation;
            //    target_rigidbody.velocity = res_spd * target_rigidbody.transform.forward - FloorNormal * 0.1f * res_spd;
            //    UpdateSlider(0, speed_restraint.Percentage(LBMath.TruncFloat(RBSpeedVectorFlat.magnitude)));
            //}

            //void walk()
            //{
            //    target_rigidbody.transform.rotation = NewRotation();
            //    target_rigidbody.velocity = NewWalkSpeed();
            //    UpdateSlider(0, speed_restraint.Percentage(LBMath.TruncFloat(RBSpeedVectorFlat.magnitude)));
            //}

            //if (bHasFloor)
            //{
            //    if (bIsWalking())
            //    {
            //        if (bCanWalkInDirection(NewWalkDirection())) // if we can walk the direction (no walls, etc)
            //        {
            //            if (bWantsToWalk()) // if we're currently walking and still want to walk
            //            {
            //                walk(); // accelerating
            //            }
            //            else // we may need to perform full stop
            //            {
            //                walk(); // braking is handled in the same func
            //            }
            //        }
            //        else // if we hit blocking a wall
            //        {
            //            SwitchState(STAND);
            //        }
            //    }
            //    else
            //    {
            //        if (bWantsToWalk()) // should accelerate from static state
            //        {
            //            if (!bHasBlockingWall())
            //                walk(); // we're accelerating now
            //            else
            //                SwitchState(STAND);
            //            // current_direction != desired_direction -- can start moveing in opposite direction (need special state)!
            //        }
            //        else
            //        {
            //            if (current_direction != desired_direction) // should start turn in place
            //            {
            //                SwitchState(TURNINPLACE);
            //            }
            //            else
            //            {
            //                SwitchState(STAND);
            //            }
            //        }
            //    }
            //}
            //else
            //{
            //    SwitchState(NOFLOOR);
            //}

            target_rigidbody.transform.rotation = Quaternion.RotateTowards(target_rigidbody.transform.rotation, NewRotation(), RotationSpeed);
            target_rigidbody.velocity           = NewWalkSpeed();
            UpdateSlider(0, speed_restraint.Percentage(LBMath.TruncFloat(RBSpeedVectorFlat.magnitude)));
        }