//method that will attachWeapons to the left hand player bone. private void attachWeaponToLeftHand(string weaponName) { //Find the weapon object on the Player Character Transform weapon = HelperK.FindSearchAllChildren(this.transform, weaponName); //Find the lWeaponBone of the player character. Searching through all children. Transform lWeaponBone = HelperK.FindSearchAllChildren(this.transform, "LHaveN"); //Remove any other children from this WeaponBone for (int i = 0; i < lWeaponBone.childCount; i++) { Destroy(lWeaponBone.GetChild(i).gameObject); } try { //make the weapon a child of the lWeaponBone, that way it will follow it in all its animations. And place its transform at the handbone location weapon.transform.parent = lWeaponBone; weapon.transform.SetPositionAndRotation(lWeaponBone.position, lWeaponBone.rotation); //compensating for our model rips base rotation being 180degrees off, which extra y rotation due to it being in the opposite of dominant hand weapon.transform.Rotate(weapon.transform.rotation.x, weapon.transform.rotation.y + 180, weapon.transform.rotation.z + 180); //if a bow do not add an additional base rotation if (weapon.name.Contains("Bow")) { weapon.transform.Rotate(weapon.transform.rotation.x, weapon.transform.rotation.y, weapon.transform.rotation.z + 180); } } catch (MissingComponentException ex) { Debug.Log("Throwing Null Exception"); } }
//method that will attachWeapons to the right hand player bone. private void attachWeaponToRightHand(string weaponName) { //Find the weapon object on the Player Character //Transform weapon = this.transform.Find(weaponName); Transform weapon = HelperK.FindSearchAllChildren(this.transform, weaponName); //Find the rWeaponBone of the player character. Searching through all children. Transform rWeaponBone = HelperK.FindSearchAllChildren(this.transform, "RHaveN"); //Remove any other children from this WeaponBone for (int i = 0; i < rWeaponBone.childCount; i++) { Destroy(rWeaponBone.GetChild(i).gameObject); } try { //make the weapon a child of the rWeaponBone, that way it will follow it in all its animations. And place its transform at the handbone location weapon.transform.parent = rWeaponBone; weapon.transform.SetPositionAndRotation(rWeaponBone.position, rWeaponBone.rotation); //compensating for our model rips base rotation being 180degrees off, weapon.transform.Rotate(weapon.transform.rotation.x, weapon.transform.rotation.y - 90, weapon.transform.rotation.z + 180); } catch (MissingComponentException ex) { Debug.Log("Throwing Null Exception"); } }
float CheckCameraPoints(Vector3 from, Vector3 to) { var nearestDistance = -1f; RaycastHit hitInfo; HelperK.ClipPlanePoints clipPlanePoints = HelperK.ClipPlaneAtNear(to); //debugging lines creation Debug.DrawLine(from, to + transform.forward * -GetComponent <Camera>().nearClipPlane, Color.red); Debug.DrawLine(from, clipPlanePoints.UpperLeft); Debug.DrawLine(from, clipPlanePoints.LowerLeft); Debug.DrawLine(from, clipPlanePoints.UpperRight); Debug.DrawLine(from, clipPlanePoints.LowerRight); Debug.DrawLine(clipPlanePoints.UpperLeft, clipPlanePoints.UpperRight); Debug.DrawLine(clipPlanePoints.UpperRight, clipPlanePoints.LowerRight); Debug.DrawLine(clipPlanePoints.LowerRight, clipPlanePoints.LowerLeft); Debug.DrawLine(clipPlanePoints.LowerLeft, clipPlanePoints.UpperLeft); if (Physics.Linecast(from, clipPlanePoints.UpperLeft, out hitInfo) && hitInfo.collider.tag != "Player") { nearestDistance = hitInfo.distance; } if (Physics.Linecast(from, clipPlanePoints.UpperRight, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) //if the new hit closer? or if we havent otherwise hit anything { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.LowerLeft, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) //if the new hit closer? or if we havent otherwise hit anything { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.LowerRight, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) //if the new hit closer? or if we havent otherwise hit anything { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, to + transform.forward * -GetComponent <Camera>().nearClipPlane, out hitInfo) && hitInfo.collider.tag != "Player") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) //if the new hit closer? or if we havent otherwise hit anything { nearestDistance = hitInfo.distance; } } return(nearestDistance); }
private void equipWeaponOnPlayerModel(string toEquip) { //create object from resources, instantiate it on the player (this script runs on the players base transform) GameObject itemToAdd = (GameObject)Resources.Load("Prefabs/" + toEquip); Instantiate(itemToAdd, this.transform); //remove excess copies HelperK.removeChild(this.transform, toEquip + "(Clone)"); }
private void findEquippedWeapon() { //find our Main Camera gameObject playerWeapon = GameObject.Find("Main Camera"); //grab our weapon bone playerWeapon = HelperK.FindSearchAllChildren(playerWeapon.transform, "WEAPON").gameObject; //find the name of the object current the child of our WEAPON bone, this way we dont need to know the name of the weapon currently equipped. We just know where it will be playerWeapon = playerWeapon.transform.GetChild(0).gameObject; }
//Initialization of Main Menu states void Awake() { //create instance, setup default states Instance = this; MainButtonsPanel = HelperK.FindSearchAllChildren(this.transform, "MainButtonsPanel").gameObject; ClassButtonsPanel = HelperK.FindSearchAllChildren(this.transform, "ClassButtonsPanel").gameObject; ClassButtonsPanel.SetActive(false); MainButtonsPanel.SetActive(true); }
void HandlePlayerInput() //function to get and handle mouse input { //get Axis input mouseX += Input.GetAxis("Mouse X") * X_MouseSensitivity; mouseY -= Input.GetAxis("Mouse Y") * Y_MouseSensitivity; //check for controller input if (Input.GetAxis("RightJoyHorizontal") > deadZone || Input.GetAxis("RightJoyHorizontal") < -deadZone) { mouseX += Input.GetAxis("RightJoyHorizontal") * X_MouseSensitivity; } if (Input.GetAxis("RightJoyVertical") > deadZone || Input.GetAxis("RightJoyVertical") < -deadZone) { mouseY -= Input.GetAxis("RightJoyVertical") * Y_MouseSensitivity; } //Limit mouse Y rotation here mouseY = HelperK.ClampAngle(mouseY, Y_MinLimit, Y_MaxLimit); }
private void equipWeaponOnPlayerModel(string toEquip, bool isShield) { //create object from resources, instantiate it on the player (this script runs on the players base transform) GameObject itemToAdd = (GameObject)Resources.Load("Prefabs/" + toEquip); Instantiate(itemToAdd, this.transform); //attach the weapon to the proper hand, adding in clone to compensate for Unity adding clone to prefabs on awake if (isShield == false) { attachWeaponToRightHand(toEquip + "(Clone)"); } else { attachWeaponToLeftHand(toEquip + "(Clone)"); } //remove excess copies HelperK.removeChild(this.transform, toEquip + "(Clone)"); }
//Handle the players mouse inputs, and respond accordingly. Handles Controller input as well. void HandlePlayerInput() { //get Axis input mouseX += Input.GetAxis("Mouse X") * X_MouseSensitivity; mouseY -= Input.GetAxis("Mouse Y") * Y_MouseSensitivity; //check for controller input, and replace mouse values with controller inputs if (Input.GetAxis("RightJoyHorizontal") > deadZone || Input.GetAxis("RightJoyHorizontal") < -deadZone) { mouseX += Input.GetAxis("RightJoyHorizontal") * X_MouseSensitivity; } if (Input.GetAxis("RightJoyVertical") > deadZone || Input.GetAxis("RightJoyVertical") < -deadZone) { mouseY -= Input.GetAxis("RightJoyVertical") * Y_MouseSensitivity; } // Limit mouse Y rotation here, so we can't go over the top of our own head. X is not required and we can spin in circles as much as we want. mouseY = HelperK.ClampAngle(mouseY, Y_MinLimit, Y_MaxLimit); }
//----------------------------------------------------------------------------BEGIN FUNCTIONS--------------------------------------------------------------------------------------// //run on game load (before start) void Awake() { CharacterController = GetComponent("CharacterController") as CharacterController; Instance = this; //grab Camera's anchor point, the Head cameraAnchorPoint = HelperK.FindSearchAllChildren(this.transform, "AnchorPointHead"); //grab the Camera focus point, (ie what we are aiming at), and the laserStartPoint for our weapon cameraFocusPoint = GameObject.Find("Camera Focus Point"); laserStartPoint = GameObject.Find("LaserStartPoint"); //grab the player models for 1st / 3rd person //TODO: Update this to work within all player model status, check model for Player Instance. For now its just testing code firstPersonModel = HelperK.FindSearchAllChildren(this.transform, "FatiguesMaleBody"); thirdPersonModel = HelperK.FindSearchAllChildren(this.transform, "Kaiden"); changeCameraState(); //grab the flashlight flashlight = HelperK.FindSearchAllChildren(this.transform.parent.transform, "FlashLight").GetComponent <FlashlightController>(); }
public void onPointerClickDelegate(PointerEventData data) { //remove the clickable from the iconName, and pass along to the onClickEquipItem function GameMenu.Instance.onClickEquipItem(HelperK.trimStringOff(iconName, "Clickable")); }
//helper function for the Occlusion system, given two vectors it checks the Clip Plane points and returns the nearest distance we can reach without occluding float CheckCameraPoints(Vector3 from, Vector3 to) { var nearestDistance = -1f; RaycastHit hitInfo; HelperK.ClipPlanePoints clipPlanePoints = HelperK.ClipPlaneAtNear(to); //debugging lines creation Debug.DrawLine(from, to + transform.forward * -GetComponent <Camera>().nearClipPlane, Color.red); Debug.DrawLine(from, clipPlanePoints.UpperLeft); Debug.DrawLine(from, clipPlanePoints.LowerLeft); Debug.DrawLine(from, clipPlanePoints.UpperRight); Debug.DrawLine(from, clipPlanePoints.LowerRight); Debug.DrawLine(clipPlanePoints.UpperLeft, clipPlanePoints.UpperRight); Debug.DrawLine(clipPlanePoints.UpperRight, clipPlanePoints.LowerRight); Debug.DrawLine(clipPlanePoints.LowerRight, clipPlanePoints.LowerLeft); Debug.DrawLine(clipPlanePoints.LowerLeft, clipPlanePoints.UpperLeft); //ensure at each step we do not hit irrelevant colliders (Player (Ourselves), Enemies, or Objects specifically marked to not have CameraCollisions) if (Physics.Linecast(from, clipPlanePoints.UpperLeft, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "IgnoreCameraCollision" && hitInfo.collider.tag != "Enemy") { nearestDistance = hitInfo.distance; } if (Physics.Linecast(from, clipPlanePoints.UpperRight, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "IgnoreCameraCollision" && hitInfo.collider.tag != "Enemy") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) //if the new hit closer? or if we havent otherwise hit anything { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.LowerLeft, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "IgnoreCameraCollision" && hitInfo.collider.tag != "Enemy") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) //if the new hit closer? or if we havent otherwise hit anything { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, clipPlanePoints.LowerRight, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "IgnoreCameraCollision" && hitInfo.collider.tag != "Enemy") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) //if the new hit closer? or if we havent otherwise hit anything { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, to + transform.forward * -GetComponent <Camera>().nearClipPlane, out hitInfo) && hitInfo.collider.tag != "Player" && hitInfo.collider.tag != "IgnoreCameraCollision" && hitInfo.collider.tag != "Enemy") { if (hitInfo.distance < nearestDistance || nearestDistance == -1) //if the new hit closer? or if we havent otherwise hit anything { nearestDistance = hitInfo.distance; } } if (Physics.Linecast(from, to + transform.forward * -GetComponent <Camera>().nearClipPlane, out hitInfo)) { Debug.Log(hitInfo.collider.tag); Debug.Log(hitInfo.collider.name); } return(nearestDistance); }