Advertisement
Guest User

Untitled

a guest
Sep 27th, 2021
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. https://www.reddit.com/r/Unity3D/comments/pvxbse/you_wanted_you_have_it_my_wardrobe_just_ran_away/
  2. using UnityEngine;
  3.  
  4. public class RunningWardrobeRigidbody : MonoBehaviour
  5. {
  6.     public Vector3 DesiredLocalRotation;
  7.     public Vector3 InfluenceAxis = new Vector3(2f, 0.05f, 1.5f);
  8.     [Range(-100f, 100f)] public float PushPower = -20f;
  9.  
  10.     private Rigidbody rig;
  11.  
  12.     private void Start()
  13.     {
  14.         rig = GetComponent<Rigidbody>();
  15.         if (rig == null) Destroy(this);
  16.     }
  17.  
  18.     public Vector3 diffsD;
  19.     private void FixedUpdate()
  20.     {
  21.         Vector3 diffs = new Vector3();
  22.         Quaternion desiredRot = Quaternion.Euler(DesiredLocalRotation);
  23.  
  24.         Quaternion xRot = Quaternion.Euler(transform.localEulerAngles.x, 0f, 0f);
  25.         Quaternion yRot = Quaternion.Euler(0f, transform.localEulerAngles.y, 0f);
  26.         Quaternion zRot = Quaternion.Euler(0f, 0f, transform.localEulerAngles.z);
  27.  
  28.         diffs.z = Vector3.SignedAngle(zRot * Vector3.up, desiredRot * Vector3.up, Vector3.forward) * InfluenceAxis.z;
  29.         diffs.y = Vector3.SignedAngle(yRot * Vector3.right, desiredRot * Vector3.right, Vector3.up) * InfluenceAxis.y;
  30.         diffs.x = Vector3.SignedAngle(xRot * Vector3.forward, desiredRot * Vector3.forward, Vector3.right) * InfluenceAxis.x;
  31.  
  32.         diffsD = diffs;
  33.  
  34.         rig.angularVelocity -= (diffs * Time.fixedDeltaTime) * Mathf.LerpUnclamped(0.0f, 1f, PushPower);
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement