void OnDeath() { if (holdingSomething) { //Gravity removed so it doesn't mess with the physics of the jumping itemCurrentlyHeld.GetComponent <Rigidbody2D>().gravityScale = GameControl.control.gravity; //Destroy the joint Destroy(holdingJoint); pickUpState = PickUpStates.notHolding; holdingSomething = false; canControl = true; //I need picked up object to have the same velocity as the Jenny when she let go. lorentzContraction.XVelocityGoal = lorentzContractionForJenny.VxNew * movement.direction.x; lorentzContraction.IsBeingHeld = false; //I'm no longer holding something holdingSomething = false; } GameControl.control.SendMessage("OnDeath"); //Pause the game with message you died! //the GUI should allow restart level //send message to the guiscript on the camera that the player is dead // it will bring up a death screen //levelDisplay.playerDead=true; levelDisplay.SendMessage("PlayerDied"); //Deactivate the player jennyShoot.enabled = false; //VectorLine.Destroy(ref jennyShoot.gunLineVec); jennyTransform.gameObject.SetActive(false); }
public void PickUp() { PickUpState = PickUpStates.gotPickedUp; foodManagerComponent.LogPickedUp(this.gameObject); PickUpState = PickUpStates.isPickedUp; FMODUnity.RuntimeManager.PlayOneShot("event:/Flappy Fly/Fly_Food"); }
void Start() { StartLocation = transform.position; PickUpState = PickUpStates.Static; foodManagerComponent = foodManagerGameObject.GetComponent <FoodManager>(); Vector3 targetPosition = gameObject.transform.position - (new Vector3(0, 1, 0)); //iTween.MoveTo(gameObject,targetPosition,10f); iTween.PunchPosition(gameObject, (new Vector3(1, 0, 0)), 1f); }
/////////////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; } }
void Update() { //Jenny's internal clock depends on the gamma factor. jennyTime += Time.deltaTime / movement.gammaX; if (Input.GetButtonDown("Jump") && canControl) { jump.lastButtonTime = Time.time; } //The applied force used here should be done in fixed update. UpdateSmoothedMovementDirection(); // Apply jumping logic if (canControl) { ApplyJumping(); } // Set rotation to the move direction if (movement.direction.sqrMagnitude > 0.01f) { Quaternion intermediateQuarenion = Quaternion.LookRotation(movement.direction); //The extra rotation of 90 degrees is so I wont have to worry about the Lorentz //contraction script acting up. Vector3 yEulerReduction = new Vector3(0.0f, 90.0f, 0.0f); intermediateQuarenion.eulerAngles -= yEulerReduction; jennyTransform.rotation = Quaternion.Slerp(jennyTransform.rotation, intermediateQuarenion, Time.deltaTime * movement.rotationSmoothing); } // Update special effects like rocket pack particle effects //UpdateEffects (); ////////////This will initiate the pickup or putdown function: if (Input.GetButtonDown("PickUp") && canControl) { //the speed is taken from the platformer controller and used to make sure that we //only pick up when Jenny is stationary. speedOfChar = Mathf.Sqrt(Mathf.Pow(GetSpeed(), 2.0f) + Mathf.Pow(GetVerticalSpeed(), 2.0f)); if (!holdingSomething && (speedOfChar < 1.5f)) { pickUpState = PickUpStates.checkBoxPresence; } else if (holdingSomething) { pickUpState = PickUpStates.puttingDown; } } ////////////THIS DEALS WITH THE PICK UP AND CARRYING OF OBJECTS /// RETURNS NULL WHEN NOTHING BEING CARRIED PickUpSwitchStatement(); }