private void FixedUpdate() { collisionDetection collisionScript = m_Rigidbody.GetComponent <collisionDetection>(); closestCheckPoint = collisionScript.closestCheckPoint; // Store the result of the function since we use it multiple times bool grounded = m_GroundingModule.grounded; if (!grounded && !falling) { m_respawnLocation = closestCheckPoint; falling = true; } if (m_Rigidbody.position.y < m_PitLevel) { Respawn(m_respawnLocation); falling = false; } if (grounded) { falling = false; } }
/** * Date: May 16, 2017 * Author: Jay Coughlan * Description: * This is the main function, overriding Unity's default behavior and creating my own. */ public override void OnInspectorGUI() { this.serializedObject.Update(); //this is the script we want to modify, we get the version of it we're looking at collisionDetection myTarget = (collisionDetection)target; //now if debug is off, we don't render the spheres at all. EditorGUI.BeginChangeCheck(); //first we reveal the debug toggle for easy debugability debug.boolValue = EditorGUILayout.Toggle("Debug", myTarget.debug); if (EditorGUI.EndChangeCheck()) { maxRend = myTarget.maximumSphere.GetComponent <Renderer>(); lay3Rend = myTarget.layer3Sphere.GetComponent <Renderer>(); lay2Rend = myTarget.layer2Sphere.GetComponent <Renderer>(); minRend = myTarget.minimumSphere.GetComponent <Renderer>(); if (debug.boolValue) { maxRend.enabled = true; lay3Rend.enabled = true; lay2Rend.enabled = true; minRend.enabled = true; } else { maxRend.enabled = false; lay3Rend.enabled = false; lay2Rend.enabled = false; minRend.enabled = false; } } //these lines make a field to input the floats for the various distances, then clamps them so they can't be //larger or smaller than each other EditorGUI.BeginChangeCheck(); //we start listening for a change min.floatValue = EditorGUILayout.FloatField("Innermost Layer", Mathf.Clamp(min.floatValue, 0, myTarget.layer2 - 0.001f)); //we apply the new value if it has changed if (EditorGUI.EndChangeCheck()) { //if there is a change we change the size of the object. myTarget.minimumSphere.transform.localScale = new Vector3(myTarget.min * 2, myTarget.min * 2, myTarget.min * 2); } //rinse, repeat for layer2 EditorGUI.BeginChangeCheck(); lay2.floatValue = EditorGUILayout.FloatField("Second Layer", Mathf.Clamp(myTarget.layer2, myTarget.min + 0.001f, myTarget.layer3 - 0.001f)); if (EditorGUI.EndChangeCheck()) { myTarget.layer2Sphere.transform.localScale = new Vector3(myTarget.layer2 * 2, myTarget.layer2 * 2, myTarget.layer2 * 2); } //rinse repeat for layer3 EditorGUI.BeginChangeCheck(); lay3.floatValue = EditorGUILayout.FloatField("Third Layer", Mathf.Clamp(myTarget.layer3, myTarget.layer2 + 0.001f, myTarget.max - 0.001f)); if (EditorGUI.EndChangeCheck()) { myTarget.layer3Sphere.transform.localScale = new Vector3(myTarget.layer3 * 2, myTarget.layer3 * 2, myTarget.layer3 * 2); } //rinse repeat for the max layer EditorGUI.BeginChangeCheck(); max.floatValue = EditorGUILayout.FloatField("Outermost Layer", Mathf.Clamp(myTarget.max, myTarget.layer3 + 0.001f, 10000f)); if (EditorGUI.EndChangeCheck()) { myTarget.maximumSphere.transform.localScale = new Vector3(myTarget.max * 2, myTarget.max * 2, myTarget.max * 2); } //this is to reveal the array of obstacles. The label is the title. EditorGUILayout.LabelField("Obstacles"); //this begins the vertical space to show the obstacles EditorGUILayout.BeginVertical(); for (int iii = 0; iii < myTarget.collidedObjects.Count; iii++) { //for each obstacle we place the name, the closest collision, the angle, and the minimum distance. //thse don't show up until the array populates. myTarget.collisions[iii] = EditorGUILayout.Vector3Field(myTarget.collidedObjects[iii].gameObject.name, myTarget.collisions[iii]); myTarget.collisionAngles[iii] = EditorGUILayout.FloatField("Angle", myTarget.collisionAngles[iii]); myTarget.collidedMinDistances[iii] = EditorGUILayout.FloatField("Min Distance", myTarget.collidedMinDistances[iii]); } EditorGUILayout.EndVertical();//end the vertical section to hold those //rinse and repeat obstacles for consumables EditorGUILayout.LabelField("Consumables"); EditorGUILayout.BeginVertical(); for (int iii = 0; iii < myTarget.consumedObjects.Count; iii++) { myTarget.consumedCollisions[iii] = EditorGUILayout.Vector3Field(myTarget.consumedObjects[iii].gameObject.name, myTarget.consumedCollisions[iii]); myTarget.consumedAngles[iii] = EditorGUILayout.FloatField("Angle", myTarget.consumedAngles[iii]); myTarget.consumedDistances[iii] = EditorGUILayout.FloatField("Distance", myTarget.consumedDistances[iii]); } EditorGUILayout.EndVertical();//end that vertical as well //EditorUtility.SetDirty(this); this.serializedObject.ApplyModifiedProperties(); }
void Update() { grabCountdown -= Time.deltaTime; // calculate instaneous velocity curVel = (transform.position - lastPos); // stamp in position for next update lastPos = transform.position; // what object being grabbed // Raycast based interaction with objects RaycastHit hit; //RaycastHit hold; Ray grabbingRay = new Ray(transform.position, Vector3.back); Debug.DrawRay(transform.position, Vector3.back * grabHeight); if (Physics.Raycast(grabbingRay, out hit, grabHeight) && hit.collider.tag == "object" && grabCountdown < 0 && Mathf.Abs(transform.position.z) < .175) { grabbedIt = true; } else { grabbedIt = false; } if (grabbedIt == true) { grabbedObjectName = hit.collider.gameObject.name; grabbedObject = GameObject.Find(grabbedObjectName); grabbedObjectPos = hit.transform; collisionDetection collide = grabbedObject.GetComponent <collisionDetection>(); // collision detection from collisionDetection.cs grabCountdown = collide.timeUntilActive; // see collisionDetection.cs this value needs to be less than 0 in order to grab grabbedObjectPos.parent = transform; // attach to parent (Player) // Vector3 returnObjtoTable = new Vector3(); // returnObjtoTable = grabbedObjectPos.position; // returnObjtoTable.z = .02f; // grabbedObjectPos.transform.position = returnObjtoTable; } else { Vector3 returnObjtoTable = new Vector3(); returnObjtoTable = grabbedObjectPos.position; returnObjtoTable.z = .00f; grabbedObjectPos.transform.position = returnObjtoTable; transform.DetachChildren(); grabbedObjectName = "none"; grabbedObject = null; grabbedIt = false; } // was an object grabbed in this frame? grabList.Add(grabbedObjectName); }
/** * Date: April 28, 2017 * Author: Aing Ragunathan * Interface: void Start () * Description: * Initializes the player when the object is created. * * Revision: Aing Ragunathan (May 3, 2017) - Updated to calibrate accelerometer. * Aing Ragunathan (May 18, 2017) - Reset points variables */ private void Start() { if (HUDCanvas == null) { Debug.LogWarning("Dude, you didn't attach a HUDCanvas. We will try and find one."); HUDCanvas = GameObject.Find("HUDCanvas"); if (HUDCanvas == null) { Debug.LogError("Dude, I couldn't find it. Please attach one."); } else { hudScript = HUDCanvas.GetComponent <HUDController>(); } } else { hudScript = HUDCanvas.GetComponent <HUDController>(); } //we will grab the Camera Position object from the Gameplay screen if we can if (gameScrnPos == null) { Debug.LogWarning("No gameplay Camera Position Object has been added. we will try to find it"); gameScrnPos = GameObject.Find("Gameplay").transform.Find("Camera Position").gameObject; if (gameScrnPos == null) { Debug.LogError("We couldn't find the Gameplay Camera Position Object!!!"); } } //we will grab the Camera position object from the Victory screen if we can if (victoryScrnPos == null) { Debug.LogWarning("No victory Camera Position Object has been added. we will try to find it"); victoryScrnPos = GameObject.Find("Victory").transform.Find("Camera Position").gameObject; if (victoryScrnPos == null) { Debug.LogError("We couldn't find the Victory Camera Position Object!!!"); } } //we will grab the camera position object from the death screen if we can if (deathScrnPos == null) { Debug.LogWarning("No death Camera Position Object has been added. we will try to find it"); deathScrnPos = GameObject.Find("Death").transform.Find("Camera Position").gameObject; if (deathScrnPos == null) { Debug.LogError("We couldn't find the death Camera Position Object!!!"); } } //getting ourselves a collisionDetection script cdScript = GameObject.Find("Collider").transform.GetChild(0).GetComponent <collisionDetection>(); //getting ourselves a screen manager script smScript = (ScreenManager)GameObject.Find("Screen Manager").GetComponent(typeof(ScreenManager)); if (rigidbody == null) { Debug.LogWarning("We have no rigidbody. we will pull one from this object."); rigidbody = GetComponent <Rigidbody>(); //get the physics of the object if (rigidbody == null) { Debug.LogError("The attached object has no rigidbody. PANIC!"); } } //we want ot grab the player's mesh renderer for the asset Ramin playerRenderer = this.transform.Find("torso").transform.Find("PlayerRenderer").GetComponent <SkinnedMeshRenderer>(); if (playerRenderer == false) { Debug.LogError("We could not find the player renderer. PANIC!"); } rigidbody.freezeRotation = true; //stop the object from rotating startPosition = transform.position; //get the starting position startRotation = new Vector3(0, 0, 1); //transform.forward; //get the starting angle of rotation levelDistance = Vector3.Distance(transform.position, GameObject.Find(endObjectName).transform.position); speedMax = speedLevelMax; //set the starting max speed playerHealth = startHealth; totalTime = 0; playerPoints = 0; finalScore = 0; recordTime = false; }