Esempio n. 1
0
 void Jump()
 {
     moveDirection.y = jumpSpeed;
     physicsFlag     = physicsState.jump;
     ySpeed          = 0;
     ySpeed         += jumpSpeed;
 }
Esempio n. 2
0
    void PhysicsFlags()
    {
        if (cc.isGrounded)
        {
            if (moveDirection != Vector3.zero)                            //If moving
            {
                if (Input.GetButton("Run") && !Input.GetButton("Crouch")) //If run is pressed but not crouch
                {
                    physicsFlag = physicsState.run;
                }
                else if (!Input.GetButton("Run") && Input.GetButton("Crouch"))               //If crouch is pressed but not run
                {
                    Crouch();
                }
                else
                {
                    UnCrouch();
                    physicsFlag = physicsState.walk;
                }
            }
            else
            {
                physicsFlag = physicsState.idle;
            }

            if (Input.GetButton("Jump"))
            {
                Jump();
            }
        }
    }
Esempio n. 3
0
 // Use this for initialization
 void Awake()
 {
     initCamPos        = cameraMain.transform.localPosition;
     physicsFlag       = physicsState.idle;
     cameraRot         = Vector3.zero;
     Screen.lockCursor = true;
     cc = GetComponent <CharacterController>();
     RagdollSwitch(false);
 }
Esempio n. 4
0
    public void Rewind()
    {
        //get all gameobjects with physics tag, then search through
        //them to find reset those components

        foreach (var iter in GetComponentsInChildren <Rigidbody>())
        {
            if (iter.tag == "can_reset")
            {
                //find object with the same name in the scene and reset. use first
                physicsState previousState = physicsHistory[0].Find(x => x.rigidState.transform.name == iter.name);

                iter.isKinematic            = previousState.rigidState.isKinematic;
                iter.angularDrag            = previousState.rigidState.angularDrag;
                iter.angularVelocity        = previousState.rigidState.angularVelocity;
                iter.centerOfMass           = previousState.rigidState.centerOfMass;
                iter.collisionDetectionMode = previousState.rigidState.collisionDetectionMode;
                iter.constraints            = previousState.rigidState.constraints;
                iter.detectCollisions       = previousState.rigidState.detectCollisions;
                iter.drag                     = previousState.rigidState.drag;
                iter.freezeRotation           = previousState.rigidState.freezeRotation;
                iter.hideFlags                = previousState.rigidState.hideFlags;
                iter.inertiaTensor            = previousState.rigidState.inertiaTensor;
                iter.inertiaTensorRotation    = previousState.rigidState.inertiaTensorRotation;
                iter.interpolation            = previousState.rigidState.interpolation;
                iter.isKinematic              = previousState.rigidState.isKinematic;
                iter.mass                     = previousState.rigidState.mass;
                iter.maxAngularVelocity       = previousState.rigidState.maxAngularVelocity;
                iter.maxDepenetrationVelocity = previousState.rigidState.maxDepenetrationVelocity;
                // iter.sleepAngularVelocity = previousState.rigidState.sleepAngularVelocity;
                iter.sleepThreshold = previousState.rigidState.sleepThreshold;
                //iter.sleepVelocity = previousState.rigidState.sleepVelocity;
                //iter.solverIterationCount = previousState.rigidState.solverIterationCount;
                iter.solverIterations = previousState.rigidState.solverIterations;
                // iter.solverVelocityIterationCount = previousState.rigidState.solverVelocityIterationCount;
                iter.solverVelocityIterations = previousState.rigidState.solverVelocityIterations;
                //iter.useConeFriction = previousState.rigidState.useConeFriction;
                iter.useGravity = previousState.rigidState.useGravity;
                iter.velocity   = previousState.rigidState.velocity;

                //copy. DONT ASSIGN BECAUSE MICROSOFT THOUGHT HAVING EVERYTHING BE A POINTER IN C# WAS A GOOD IDEA
                iter.gameObject.transform.position   = new Vector3(previousState.position.x, previousState.position.y, previousState.position.z);
                iter.gameObject.transform.rotation   = new Quaternion(previousState.rotation.x, previousState.rotation.y, previousState.rotation.z, previousState.rotation.w);
                iter.gameObject.transform.localScale = new Vector3(previousState.scale.x, previousState.scale.y, previousState.scale.z);
            }
        }

        //now pop it off. (if only one left, leave it alone)
        if (physicsHistory.Count > 1)
        {
            physicsHistory.RemoveAt(0);
        }
    }
Esempio n. 5
0
 void RagdollSwitch(bool state)
 {
     if (state)
     {
         physicsFlag = physicsState.dead;
         model.animation.Stop();
         cameraMain.transform.parent = head;
     }
     for (int i = 0; i < ragdoll.Length; i++)
     {
         ragdoll[i].isKinematic            = !state;
         model.animation.playAutomatically = !state;
         model.animation.animatePhysics    = state;
     }
 }
Esempio n. 6
0
 void Crouch()
 {
     cameraMain.transform.position = new Vector3(cameraMain.transform.position.x, head.transform.position.y, cameraMain.transform.position.z);
     physicsFlag = physicsState.crouch;
     //Revise character controller height
     if (cc.height > 1.4)
     {
         cc.height *= .99f;
     }
     //Revise character controller center
     if (cc.center.y > 0.7)
     {
         cc.center = new Vector3(cc.center.x, cc.center.y * .99f, cc.center.z);
     }
 }
    physicsState EulerFunction(float h, physicsState state0)
    {
        physicsState state1;
        Vector3      accel = Physics.gravity;

        accel *= airResistance;

        if (state0.position.x >= 3f)
        {
            state0.velocity += windVelocity;
        }

        state1.t        = state0.t + h;
        state1.velocity = state0.velocity + (accel * h);
        state1.position = state0.position + (h * state0.velocity);
        return(state1);
    }
    private void Prediction()
    {
        physicsState currentState = new physicsState(0, transform.position, initialVeclocity);
        physicsState nextState    = currentState;

        while (currentState.position.y >= 0)
        {
            nextState = EulerFunction(hStep, currentState);
            linePositions.Add(nextState.position);
            currentState = nextState;
        }

        /*for (int i = 0; i < 10; i++) {
         *  nextState = EulerFunction(hStep, currentState);
         *  linePositions.Add(nextState.position);
         *  currentState = nextState;
         * }*/
    }