Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        //Get the speed of light from the platformer controler
        //as well as Jenny's speed.
        player = GameObject.Find("Jenny");
        platformerController = player.GetComponent("PlatformerController") as PlatformerController;
        //The script needs to access PickingUpObjects script on Jenny
        //pickingUpObjects = player.GetComponent("PickingUpObjects") as PickingUpObjects;

        timer = transform.parent.FindChild("Timer") as Transform;


        //physConst = GameObject.Find ("PhysicalConstants");
        //physicsConstants = physConst.GetComponent("PhysicsConstants") as PhysicsConstants;
        //SpeedOfLight=physicsConstants.SpeedOfLight;

        lorentzContraction = transform.GetComponent("LorentzContraction")
                             as LorentzContraction;

        //	explosionInitiated = false;



        bombExplosionSpawner = transform.parent.GetComponent("BombExplosionSpawner") as BombExplosionSpawner;
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (blockDead)
        {
            ///Let's have the block flash for a second until it disapears
            this.GetComponent <Renderer>().material.SetFloat("_DissolveVal", Mathf.Lerp(1.2f, -0.199f,
                                                                                        (Time.time - timeOfDestruction) * oneOverFlashTime));

            /*
             * if(Time.time > timeOfLastFlash + durationOfFlash) {
             *      if (transform.renderer.enabled == true){
             *              transform.renderer.enabled = false;
             *      } else {
             *              transform.renderer.enabled = true;
             *      }
             *      //GetComponent(MeshRenderer).enabled = false;
             *      timeOfLastFlash= Time.time;
             * }*/

            if (Time.time > timeOfDestruction + totalFlashTime)
            {
                //if is being held, send message to jenny that it is getting droped
                lC = transform.GetComponent("LorentzContraction") as LorentzContraction;
                if (lC.IsBeingHeld || lC.IsBeingPickedUp)
                {
                    PlatformerController.platformerController.pickUpState = PlatformerController.PickUpStates.objectDestroyed;
                }

                Destroy(gameObject);
            }
        }
    }
Esempio n. 3
0
    // Use this for initialization
    void Start()
    {
        lorentzContraction = transform.GetComponent("LorentzContraction")
                             as LorentzContraction;

        explosion = transform.GetComponent("ExplosionOfBomb")
                    as ExplosionOfBomb;
        //We need to use a common parent so the clock won't be lorentz contracted
        bombParent = transform.parent;
        timer      = bombParent.FindChild("Timer").gameObject;   //
        audioPitch = timer.GetComponent <AudioSource>().pitch;


        clockStarted  = false;
        clockCounting = false;
        //boom          = false;
        bodyTime = 0.0f;

        //This is the fuse length of the bomb.
        fuseLength = 8.0f;

        gammaX = 1.0f;
    }
/////////////This is the algorythm that picks up the carried object
    void PickUpSwitchStatement()
    {
        //notHolding       //if not holding, the statement is ignored
        //checkBoxPresence,//checks that it is alright to pick something up
        //automateLift,    // lifts the object into position
        //attachJoint,     // joins the object to Jenny
        //pickUpInterupted,//drops the object, halts the process if interupted
        //pickUpComplete,  // move object around with Jenny
        //puttingDown      //puts down the object, sets state to not holding

        switch (pickUpState)
        {
        case (PickUpStates.notHolding):
            break;            //this is the default state of the pick up loop

        //In the check box line we see if there is a box to pick up,
        //if the is remove control and set the pickupstate to picking up something
        case (PickUpStates.checkBoxPresence):
            directionOfCharacter = GetDirection();
            liftStartTime        = Time.time;
            pickUpRayStart       = new Vector2(jennyTransform.position.x,
                                               jennyTransform.position.y - 0.5f * jennyTransform.localScale.y);
            hit2 = Physics2D.Raycast(pickUpRayStart,
                                     new Vector2(directionOfCharacter.x, 0.0f)
                                     , 4.5f, 1 << 8);
            //layer of pickuppable stuff is 8.
            if (hit2.collider != null)
            {
                //Debug.Log ("The hit object is called"+ hit2.transform.name);
//				Physics2D.Raycast (pickUpRayStart, new Vector2(directionOfCharacter.x,0.0f)  ,  4.5f , layerMaskOfHit)
//				&& hit2.collider.CompareTag ("PickUp")



                jennyShoot.heldObject = hit2.transform;
                jennyShoot.shotState  = JennyShoot.ShotState.startHolding;
                //jennyShoot.canShoot = false;



                //There is a box in front of the character it is picked up prefferentially
//				typeOfPickUp = "fromSide";
                automatedPickUpComplete = false;
                //Remove control from the character Controller during the animation
                canControl = false;
                //the transform of the pick up box;
                itemCurrentlyHeld = hit2.transform;
                //Gravity removed so it doesn't mess with the physics of the jumping
                itemCurrentlyHeld.GetComponent <Rigidbody2D>().gravityScale = 0.0f;
                itemCurrentlyHeld.GetComponent <Rigidbody2D>().isKinematic  = false;
                //assign the mass of the objec for reference
                massOfObjInitial = itemCurrentlyHeld.GetComponent <Rigidbody2D>().mass;



                //this still doesn't work if the two colliders are touching sweeptest doesn't work here


                ///////////////////////////////
                ///////////////////////////////
                //There is more than one type of lorentz contraction
                //it depends on what kind of box we are picking up.
                ///////////////////////////////
                ///////////////////////////////
                lorentzContraction =
                    itemCurrentlyHeld.GetComponent("LorentzContraction")
                    as LorentzContraction;
                //This allows a c
                lorentzContraction.IsBeingPickedUp = true;

                //We need to set the carried objects scale back to it's original settings
                itemCurrentlyHeld.localScale = new Vector3(lorentzContraction.xScale0,
                                                           lorentzContraction.yScale0, lorentzContraction.zScale0);

                //We need to remove the rigidbody x constraint
                //CONSTRAINT MUST BE DONE WITH A JOINT
                //hit2.transform.rigidbody2D.constraints = RigidbodyConstraints.FreezePositionZ
                //	|RigidbodyConstraints.FreezeRotation;
                lorentzContraction.xMotionStatic = false;



                //The initial position is needed to do the lift
                initialXposition = itemCurrentlyHeld.position.x;
                //initialHeightOfCarried = itemCurrentlyHeld.position.y;
                //liftStartTime = Time.time;


                //the goal height will be how far above Jenny the block must be (shouldn't calculate more than once.
                goalHeight     = 0.5f * jennyTransform.localScale.y + 7.0f + 0.5f * itemCurrentlyHeld.localScale.y;
                riseSpeed      = goalHeight / riseTime;
                slideOverSpeed = jennyTransform.localScale.x / riseTime;

                //make the object lighter for transport and lift
                itemCurrentlyHeld.GetComponent <Rigidbody2D>().mass = massOfObjCarried;

                //This moves the switch statement to the next part of the loop
                pickUpState = PickUpStates.automateLift;
                goto case PickUpStates.automateLift;
            }
            else
            {
                //If there is no box to pick up, leave the loop
                pickUpState = PickUpStates.notHolding;
                break;
            }

        case (PickUpStates.automateLift):

            //interupt the lift if it takes too long
            if (Time.time > liftStartTime + maxLiftDuration)
            {
                pickUpState = PickUpStates.pickUpInterupted;
                goto case PickUpStates.pickUpInterupted;
            }


            if (!automatedPickUpComplete)
            {
                if (itemCurrentlyHeld == null)
                {
                    pickUpState = PickUpStates.pickUpInterupted;
                    goto case PickUpStates.pickUpInterupted;
                }
                else
                {
                    automatedPickUpComplete = pickUpAutomation();                     //typeOfPickUp);
                    break;
                }
            }
            else
            {
                pickUpState = PickUpStates.attachJoint;
                goto case PickUpStates.attachJoint;
            }

        case (PickUpStates.attachJoint):

            //interupt the lift if it takes too long
            if (Time.time > liftStartTime + maxLiftDuration)
            {
                pickUpState = PickUpStates.pickUpInterupted;
                goto case PickUpStates.pickUpInterupted;
            }

            //Initialize the joint.
            holdingJoint = jennyTransform.gameObject.AddComponent <SliderJoint2D> ();
            //The carried objects can only pivot around the z axis
            //holdingJoint.axis = new Vector2 (0.0f, 1.0f);
            //The carried object will be a short distance from
            holdingJoint.connectedBody = itemCurrentlyHeld.GetComponent <Rigidbody2D>();

            holdingJoint.angle     = 0.0f;
            holdingJoint.anchor    = new Vector2(0.0f, goalHeight / jennyTransform.localScale.y);
            holdingJoint.useLimits = true;
            //holdingJoint2.xMotion = ConfigurableJointMotion.Limited;
            //Define DeltaXShift to be used by the carried object's script LorentzContractions
            //DeltaXShift = (itemCurrentlyHeld.position.x - jennyTransform.position.x);


            lorentzContraction.IsBeingHeld = true;

            holdingSomething = true;



            //We need to remove the rigidbody x constraint
            //CONSTRAINT MUST BE DONE WITH A JOINT
            //hit2.transform.rigidbody.constraints = RigidbodyConstraints.FreezePositionZ
            //	|RigidbodyConstraints.FreezeRotation;
            lorentzContraction.xMotionStatic = false;



            //directionAtPickUp=Mathf.Sign(movement.direction.x);
            //The maximum range of xcoordinate is set up by playing
            //with the joint limits
            SoftJointLimit holdingJointLimits = new SoftJointLimit();

            //holdingJointLimits.spring = 0.0f;
            //holdingJointLimits.damper = 0.0f;
            holdingJointLimits.bounciness = 0.0f;

            holdingJointLimits.limit = lorentzContraction.xScale0;


            //holdingJointLimits.limit = lorentzContraction.xScale0;
            //holdingJoint2.linearLimit = holdingJointLimits;

            //The holding joint's target position is defaulted to zero
            //holdingJoint2.targetPosition = new Vector3 (0.0f, 0.0f, 0.0f);

            //The carried object is driven with this force
            JointDrive holdingJointDrive = new JointDrive();
            holdingJointDrive.mode           = JointDriveMode.Position;
            holdingJointDrive.positionSpring = 500.0f;
            holdingJointDrive.positionDamper = 0.0f;
            holdingJointDrive.maximumForce   = Mathf.Infinity;
            //holdingJoint2.yDrive = holdingJointDrive;


            //Return control to the character Controller
            canControl = true;


            //Define DeltaXShift to have correct lorentz contractions
            //see the update loop.
            //DeltaXShift = (itemCurrentlyHeld.position.x - jennyTransform.position.x);


            pickUpState = PickUpStates.pickUpComplete;
            break;

        case (PickUpStates.pickUpInterupted):
            //If the lift is interupted in any way this gets called
            //May need a different one if it is mid-top-lift

            if (itemCurrentlyHeld != null)
            {
                //return mass to original mass just in case;
                itemCurrentlyHeld.GetComponent <Rigidbody2D>().mass = massOfObjInitial;
                //I need to turn gravity back on for the carried object
                itemCurrentlyHeld.GetComponent <Rigidbody2D>().gravityScale = GameControl.control.gravity;
            }


            //Return control to the character Controller
            canControl = true;

            //JENNY CAN SHOOT AGAIN
            jennyShoot.shotState = JennyShoot.ShotState.turnOnShoot;
            //jennyShoot.canShoot = true;
            jennyShoot.heldObject = null;


            pickUpState = PickUpStates.notHolding;
            break;

        case (PickUpStates.pickUpComplete):


            //The carried box needs to stay centered even under lorentz contraction
            directionOfCharacter = GetDirection();
            gammaX = lorentzContractionForJenny.gammaX;
            //hold

            //holdingJoint2.targetPosition = new Vector3 (0.0f,
            //                                            DeltaXShift * directionOfCharacter.x * (1 - 1 / gammaX),
            //                                            0.0f);
            break;



        case (PickUpStates.puttingDown):
            lorentzContraction.IsBeingHeld = false;

            //Gravity removed so it doesn't mess with the physics of the jumping
            itemCurrentlyHeld.GetComponent <Rigidbody2D>().gravityScale = GameControl.control.gravity;

            Destroy(holdingJoint);
            holdingSomething = false;
            canControl       = true;


            //SET MOVEMENT SPEED TO ZERO WHEN SOMETHING LET GO
            movement.targetSpeed = 0.0f;
            movement.gammaX      = 1f;
            lorentzContractionForJenny.gammaX = 1.0f;


            //I need picked up object to have the same velocity as the Jenny when she let go.

            if (gammaX < 1.5f)
            {
                //If jenny is moving slowly, actively push the block off so it doesn't land on her if possibel
                lorentzContraction.XVelocityGoal = GetVxTargetFromGammaX(1.5f)               //lorentzContractionForJenny.GetXVelocity VxNew
                                                   * movement.direction.x;
            }
            else
            {
                lorentzContraction.XVelocityGoal = lorentzContractionForJenny.VxNew
                                                   * movement.direction.x;
            }

            //bumb the carried object a little so it moves away from Jenny.
            itemCurrentlyHeld.transform.GetComponent <Rigidbody2D>().velocity += new Vector2(0.0f, 10.0f);

            //set the objects mass back to original
            itemCurrentlyHeld.GetComponent <Rigidbody2D>().mass = massOfObjInitial;


            //JENNY CAN SHOOT AGAIN
            jennyShoot.shotState = JennyShoot.ShotState.turnOnShoot;
            //jennyShoot.canShoot = true;
            jennyShoot.heldObject = null;



            //When the object is released the state goes back to not holding
            pickUpState = PickUpStates.notHolding;
            break;

        case (PickUpStates.objectDestroyed):
            //has the object been destroyed while being carried?

            lorentzContraction.IsBeingHeld = false;


            Destroy(holdingJoint);
            holdingSomething = false;
            canControl       = true;


            //JENNY CAN SHOOT AGAIN
            jennyShoot.shotState = JennyShoot.ShotState.turnOnShoot;
            //jennyShoot.canShoot = true;
            jennyShoot.heldObject = null;



            //When the object is released the state goes back to not holding
            pickUpState = PickUpStates.notHolding;
            break;
        }
    }