Exemple #1
0
 void OnDestroy()
 {
     if (Body != null)
     {
         JPhysics.RemoveBody(this);
     }
 }
Exemple #2
0
 void OnDisable()
 {
     if (Body != null)
     {
         JPhysics.RemoveBody(this);
     }
 }
Exemple #3
0
 void Awake()
 {
     instance = this;
     settings = Resources.Load("JSettings") as JSettings;
     CreateWorld();
     thread = new Thread(Logic);
     timer  = new Timer(Loop, null, 0, (int)(timestep * 1000));
 }
Exemple #4
0
 static void CheckInstance()
 {
     if (instance == null && Application.isPlaying)
     {
         instance = new GameObject("JPhysics", typeof(JPhysics)).GetComponent <JPhysics>();
         instance.gameObject.hideFlags = HideFlags.HideAndDontSave;
         UnityEngine.Debug.Log("Phisics Manager missing. New manager Instance has been created.");
     }
 }
Exemple #5
0
 void Awake()
 {
     instance = this;
     settings = Resources.Load("JSettings") as JSettings;
     CreateWorld();
     thread = new Thread(Logic);
     timer = new Timer(Loop, null, 0, (int)(timestep*1000));
 }
Exemple #6
0
 static void CheckInstance()
 {
     if (instance == null && Application.isPlaying)
     {
         instance = new GameObject("JPhysics", typeof(JPhysics)).GetComponent<JPhysics>();
         instance.gameObject.hideFlags = HideFlags.HideAndDontSave;
         UnityEngine.Debug.Log("Phisics Manager missing. New manager Instance has been created.");
     }
 }
Exemple #7
0
        void OnEnable()
        {
            if (IsCompound)
            {
                return;
            }
            collider = GetComponent <JCollider>();
            if (collider == null)
            {
                Debug.LogWarning("No Collider Found!");
                enabled = false;
                return;
            }
            if (collider.IsTrigger)
            {
                enabled = false;
                return;
            }
            lastPosition = transform.position;
            Body         = new RigidBody(collider.Shape)
            {
                Position    = transform.position.ConvertToJVector(),
                Orientation = transform.rotation.ConvertToJMatrix(),
                IsStatic    = isStatic,
                Mass        = mass,

                AffectedByGravity = useGravity,
                Damping           = (Damping == DampingType.Angular)
                                  ? Damp.Angular
                                  : (Damping == DampingType.Linear)
                                        ? Damp.Linear
                                        : (Damping == DampingType.AngularAndLinear)
                                              ? Damp.Linear | Damp.Angular
                                              : Damp.None
            };
            var m = collider.Material;

            if (m != null)
            {
                Body.Material = new Dynamics.Material
                {
                    KineticFriction = m.dynamicFriction,
                    StaticFriction  = m.staticFriction,
                    Restitution     = m.bounciness
                }
            }
            ;
            JPhysics.AddBody(this);
        }

        void Update()
        {
            if (!collider.IsTrigger)
            {
                var pos = transform.position;
                var rot = transform.rotation;
                if (lp != pos || lr != rot)
                {
                    cp = pos;
                    cr = rot;
                    JPhysics.Correct(this);
                }
                lp = transform.position = Vector3.Lerp(pos, lastPosition, LerpFactor);
                lr = transform.rotation = Quaternion.Lerp(rot, lastRotation, LerpFactor);
            }
            else
            {
                enabled = false;
            }
        }