Exemplo n.º 1
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);
        }
Exemplo n.º 2
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;
            }
        }