void PlayerControl() { if (input.myTeam == TeamAssignment.Team.TEAM_A) { foreach (string button in input.p1Inputs) { if (!Input.GetButtonDown(button)) { health.vulnerable = false; fuel.usingFuel = false; rb.isKinematic = false; EnableSwitching(true); } } } else { foreach (string button in input.p2Inputs) { if (!Input.GetButtonDown(button)) { health.vulnerable = false; fuel.usingFuel = false; rb.isKinematic = false; EnableSwitching(true); } } } float controllerVertical = Input.GetAxis(input.vertical); float controllerHorizontal = Input.GetAxis(input.horizontal); if (fuel.Fuel > 0) { rb.AddForce(controllerHorizontal * Time.deltaTime * speed, 0f, controllerVertical * Time.deltaTime * speed, ForceMode.Impulse); } if (controllerVertical != 0 || controllerHorizontal != 0) { EnableSwitching(false); health.vulnerable = true; fuel.usingFuel = true; fuel.DecreaseFuel(stats.moveFuelDepleteRate); } if (Input.GetButtonDown(input.fire)) { EnableSwitching(false); rb.isKinematic = true; if (GetComponentInChildren <CatchzoneScript> ().isReady) { bullet = GetComponentInChildren <CatchzoneScript> ().bullet; bullet.SetParent(transform); bullet.transform.position = GetComponentInChildren <CatchzoneScript> ().transform.position; bulletRB = bullet.gameObject.GetComponent <Rigidbody> (); velo = bulletRB.velocity.magnitude; print("Bullet Velocity: " + velo); bulletRB.isKinematic = true; bullet.transform.localScale *= 2; bullet.GetComponent <BulletScript>().released = false; StartCoroutine("ChargeProjectile", bullet.gameObject); } } if (Input.GetButtonUp(input.fire) || fuel.Fuel == 0) { EnableSwitching(true); rb.isKinematic = false; newVelo = velo * multiplier; if (bullet != null && bullet.GetComponent <BulletScript>().released == false) { ReleaseProjectile(newVelo); multiplier = 0f; } } if (!Mathf.Approximately(Input.GetAxis(input.rStick2), 0f)) { health.vulnerable = true; } transform.Rotate(0f, Input.GetAxis(input.rStick2) * Time.deltaTime * 200f, 0f); }
void PlayerControl() { if (input.myTeam == TeamAssignment.Team.TEAM_A) { foreach (string button in input.p1Inputs) { if (!Input.GetButton(button)) { health.vulnerable = false; fuel.usingFuel = false; // rb.isKinematic = true; EnableSwitching(true); } else { health.vulnerable = true; fuel.usingFuel = true; // rb.isKinematic = false; // EnableSwitching(false); break; } } } else if (input.myTeam == TeamAssignment.Team.TEAM_B) { foreach (string button in input.p2Inputs) { if (!Input.GetButton(button)) { health.vulnerable = false; fuel.usingFuel = false; // rb.isKinematic = true; EnableSwitching(true); } else { health.vulnerable = true; fuel.usingFuel = true; // rb.isKinematic = false; EnableSwitching(false); break; } } } float controllerVertical = Input.GetAxis(input.vertical); float controllerHorizontal = Input.GetAxis(input.horizontal); float horizontalPos = transform.position.x + controllerHorizontal * Time.deltaTime * currentSpeed; float verticalPos = transform.position.z + controllerVertical * Time.deltaTime * currentSpeed; if (fuel.Fuel > 0) { transform.position = new Vector3(horizontalPos, transform.position.y, verticalPos); Vector3 movement = new Vector3(controllerHorizontal, 0f, controllerVertical); // rb.AddForce (movement * currentSpeed * Time.deltaTime * 10f, ForceMode.Impulse); } if (controllerVertical != 0 || controllerHorizontal != 0) { health.vulnerable = true; fuel.usingFuel = true; EnableSwitching(false); // rb.isKinematic = false; fuel.DecreaseFuel(stats.moveFuelDepleteRate); } // // if (Input.GetButton ("PS4_R1")) { // playerMoving = true; // float angle = 1f * Time.deltaTime * rotationSpeed; // if (transform.eulerAngles.y <= maxRotationRight) { // transform.Rotate (0f, angle, 0f); // } // } else { // float angle = -1f * Time.deltaTime * rotationSpeed * snapBackMod; // if (transform.eulerAngles.y > defaultRotation) { // // transform.Rotate (0f, angle, 0f); // } // } if (Input.GetButton(input.rewind)) { health.vulnerable = true; fuel.usingFuel = true; fuel.DecreaseFuel(stats.actionFuelDepleteRate); EnableSwitching(false); float elevation = transform.position.y + 1f * Time.deltaTime * jumpSpeed; if (fuel.Fuel > 0) { if (elevation < maxLift) { transform.position = new Vector3(horizontalPos, elevation, verticalPos); } else { transform.position = new Vector3(horizontalPos, maxLift, verticalPos); } } else { elevation = transform.position.y + -1f * Time.deltaTime * jumpSpeed * 2f; if (elevation > defaultLift) { transform.position = new Vector3(horizontalPos, elevation, verticalPos); } else { transform.position = new Vector3(horizontalPos, defaultLift, verticalPos); } } } else { float elevation = transform.position.y + -1f * Time.deltaTime * jumpSpeed * 2f; if (elevation > defaultLift) { transform.position = new Vector3(horizontalPos, elevation, verticalPos); } else { transform.position = new Vector3(horizontalPos, defaultLift, verticalPos); // fuel.usingFuel = false; } } if (Input.GetButtonUp(input.rewind)) { fuel.usingFuel = false; EnableSwitching(true); } if (Input.GetButtonDown(input.fire)) { if (!projectileExist) { if (fuel.Fuel > 0) { bulletInstance = Instantiate(projectile, transform.position + transform.forward * 2f, Quaternion.identity, transform); bulletInstance.GetComponent <BulletScript>().released = false; bulletInstance.GetComponent <BulletScript>().playerNum = playerNum; bulletInstance.GetComponent <Collider> ().enabled = false; StartCoroutine("ChargeProjectile", bulletInstance); projectileExist = true; } } } if (Input.GetButtonUp(input.fire)) { EnableSwitching(true); // fuel.usingFuel = false; currentSpeed = defaultSpeed; if (bulletInstance != null && bulletInstance.GetComponent <BulletScript>().released == false) { bulletInstance.GetComponent <Collider> ().enabled = true; Rigidbody rb = bulletInstance.GetComponent <Rigidbody> (); rb.isKinematic = false; rb.AddForce(transform.forward * projectilePower * Time.deltaTime * 100f, ForceMode.Impulse); bulletInstance.transform.parent = null; bulletInstance.GetComponent <BulletScript>().released = true; } } // float turnAngle = Input.GetAxis ("PS4_RSTICK") * Time.deltaTime * rotationSpeed; // if (!Mathf.Approximately(Input.GetAxis("PS4_RSTICK"),0f)){ // health.vulnerable = true; // } if (playerNum == 1) { float playerRotation = Util.remapRange(Input.GetAxis(input.rStick), -1, 1, maxRotationLeft, maxRotationRight); if (transform.eulerAngles.y <= maxRotationRight && transform.eulerAngles.y >= maxRotationLeft) { // transform.Rotate (0f, turnAngle, 0f); transform.eulerAngles = new Vector3(transform.eulerAngles.x, playerRotation, transform.eulerAngles.z); } else { transform.eulerAngles = new Vector3(transform.eulerAngles.x, defaultRotation, transform.eulerAngles.z); } } else { float playerRotation = Util.remapRange(Input.GetAxis(input.rStick), 1, -1, maxRotationLeft, maxRotationRight); if (transform.eulerAngles.y <= maxRotationRight && transform.eulerAngles.y >= maxRotationLeft) { // Debug.Log ("Within angle"); // transform.Rotate (0f, turnAngle, 0f); transform.eulerAngles = new Vector3(transform.eulerAngles.x, playerRotation, transform.eulerAngles.z); } else { // Debug.Log ("Not within angle"); transform.eulerAngles = new Vector3(transform.eulerAngles.x, defaultRotation, transform.eulerAngles.z); } } if (gameObject.activeSelf == false) { // Debug.Log ("Inactive"); Destroy(bulletInstance); } }
void PlayerControl() { if (input.myTeam == TeamAssignment.Team.TEAM_A) { foreach (string button in input.p1Inputs) { if (!Input.GetButtonDown(button)) { if (!hasJumped) { health.vulnerable = false; } fuel.usingFuel = false; EnableSwitching(true); } } } else { foreach (string button in input.p2Inputs) { if (!Input.GetButtonDown(button)) { if (!hasJumped) { health.vulnerable = false; } fuel.usingFuel = false; EnableSwitching(true); } } } float controllerVertical = Input.GetAxis(input.vertical); float controllerHorizontal = Input.GetAxis(input.horizontal); float rstickVertical = Input.GetAxis(input.rStick); float rstickHorizontal = Input.GetAxis(input.rStick2); // if (controllerVertical != 0 || controllerHorizontal != 0) { // health.vulnerable = true; // } if (!Input.GetButton(input.rewind)) { float angle = Mathf.Atan2(rstickHorizontal, rstickVertical) * Mathf.Rad2Deg; // transform.rotation = Quaternion.Euler(new Vector3(0, angle, 0)); transform.RotateAround(transform.position, transform.up, angle * Time.deltaTime); // transform.Rotate (0f, angle * Time.deltaTime, 0f); } if (controllerVertical != 0) { health.vulnerable = true; EnableSwitching(false); if (fuel.Fuel > 0) { fuel.usingFuel = true; rb.AddForce(transform.forward * Time.deltaTime * speed * controllerVertical, ForceMode.Force); fuel.DecreaseFuel(stats.moveFuelDepleteRate); } } if (Input.GetButton(input.rewind)) { if (!isJumping && !hasJumped) { midXMod = 3f; midYMod = 1f; endXMod = 6f; endYMod = -1f; Vector3 midDir = transform.forward * midXMod + transform.up * midYMod; Vector3 endDir = transform.forward * endXMod + transform.up * endYMod; Vector3 midPos = transform.position + midDir; Vector3 endPos = transform.position + endDir; if (midPoint == null && endPoint == null) { midPoint = Instantiate(marker, midPos, Quaternion.identity, transform) as GameObject; endPoint = Instantiate(marker, endPos, Quaternion.identity, transform) as GameObject; isJumping = true; } } EnableSwitching(false); if (isJumping) { if (midPoint != null && endPoint != null) { // fuel.usingFuel = true; float dist = Vector3.Distance(transform.position, endPoint.transform.position); float midPosMod = -Input.GetAxis(input.rStick2) * Time.deltaTime; float endPosMod = Input.GetAxis(input.rStick2) * Time.deltaTime; if (dist >= maxJumpDistance && Input.GetAxis(input.rStick2) > 0) { midPoint.transform.position = midPoint.transform.position; endPoint.transform.position = endPoint.transform.position; } else if (dist <= minJumpDistance && Input.GetAxis(input.rStick2) < 0) { midPoint.transform.position = midPoint.transform.position; endPoint.transform.position = endPoint.transform.position; } else { midPoint.transform.position = midPoint.transform.position + transform.up * midPosMod; endPoint.transform.position = endPoint.transform.position + transform.forward * endPosMod; } } } } if (Input.GetButtonUp(input.rewind)) { if (!hasJumped) { isJumping = false; hasJumped = true; rb.useGravity = false; if (endPoint != null) { endPos = new Vector3(endPoint.transform.position.x, endPoint.transform.position.y - endYMod, endPoint.transform.position.z); } if (midPoint != null) { midPos = new Vector3(midPoint.transform.position.x, midPoint.transform.position.y, midPoint.transform.position.z); } if (!Input.GetButton(input.cancel)) { StartCoroutine(ExecuteJump(midPos, endPos)); } else { hasJumped = false; } } if (midPoint != null && endPoint != null) { Destroy(midPoint.gameObject); Destroy(endPoint.gameObject); } } }