public void OnAxeCalled() { if ((axeState == AxeState.Travelling || axeState == AxeState.Thrown || axeState == AxeState.Grabbled) && isAvailableToReturn) { rb.velocity = Vector3.zero; rb.angularVelocity = Vector3.zero; returningStartTime = Time.time; returningStartPosition = gameObject.GetComponent <Rigidbody>().transform.position; journeyLength = Vector3.Distance(returningStartPosition, rHand.position); if (journeyLength < 6) { throwedToClose = true; } else { throwedToClose = false; if (transform.forward.z < 0) { returningMiddlePosition = returningStartPosition + (rHand.position - returningStartPosition) / 2 + (-Vector3.forward * returnArcZ); } else { returningMiddlePosition = returningStartPosition + (rHand.position - returningStartPosition) / 2 + (Vector3.forward * returnArcZ); } } axeState = AxeState.Returning; } }
public override void GrabEnd(Vector3 linearVelocity, Vector3 angularVelocity) { rb.isKinematic = false; if (Mathf.Abs((int)angularVelocity.x) < angularVelocityThreshold) { Physics.gravity = normalGravity; rb.useGravity = true; rb.velocity = linearVelocity; } else { rb.velocity = linearVelocity * 2; Physics.gravity = travellingGravity; rb.useGravity = true; axeState = AxeState.Travelling; } rb.angularVelocity = angularVelocity; linearVelocityWhenGrabEnd = linearVelocity; angularVelocityWhenGrabEnd = angularVelocity; StartCoroutine(WaitForReturnCoroutine()); m_grabbedBy = null; m_grabbedCollider = null; }
void FixedUpdate() { if (Input.GetMouseButtonDown(0)) { axeState = AxeState.Thrown; } if (Input.GetMouseButtonDown(1)) { startPos = axe.transform.position; endPos = axeTempHolder.transform.position; startTime = Time.time; journeyLength = Vector3.Distance(startPos, endPos); axeState = AxeState.Returning; } if (axeState == AxeState.Thrown) { ThrownAxeWithPhysics(); } if (axeState == AxeState.Travelling || axeState == AxeState.Returning) { axe.transform.Rotate(6.0f * axeRotationSpeed * Time.deltaTime, 0, 0); } if (axeState == AxeState.Returning) { RecallAxe(); } }
public AnimatedTexture this[AxeState s] { get { return(textures[s]); } }
void ThrownAxeWithPhysics() { axe.transform.parent = null; axeState = AxeState.Travelling; axeRb.isKinematic = false; axeRb.useGravity = true; axeRb.AddForce(axe.transform.forward * axeThrowPower); }
private void OnCollisionEnter(Collision collision) { if (collision.transform.tag == "Ground") { Debug.Log("Ground"); axeState = AxeState.DEFAULT; } }
void ThrownAxeWithPhysic() { axe.transform.parent = null; axeState = AxeState.Travelling; rb.isKinematic = false; // rb.useGravity = true; rb.AddForce(Camera.main.transform.forward * axeThrowPower); AxeCollider.enabled = true; }
void RecalledAxe() { axeState = AxeState.Static; axeCollsions.RemoveConstraints(); axe.transform.position = axeTempHolder.transform.position; axe.transform.rotation = axeTempHolder.transform.rotation; axeRb.isKinematic = true; axeRb.useGravity = false; axe.transform.parent = this.transform; }
void FixedUpdate() { if (Input.GetAxisRaw("Triggers") == 1 && godMode.godModeState == GodMode.GodModeState.turnedOFF && timebtwShooting <= 0) { GameObject _bullet = Instantiate(bullet, GunNozzle.position, Quaternion.identity); _bullet.GetComponent <Rigidbody>().AddForce(transform.TransformDirection(Vector3.forward) * BulletSpeed, ForceMode.Impulse); Destroy(_bullet, 5f); timebtwShooting = FireRate; } else { timebtwShooting -= Time.deltaTime; } if (godMode.godModeState == GodMode.GodModeState.turnedOFF) { endPos = axeTempHolder.transform.position; camPos = player.position; if (Input.GetButtonDown("R1") && axe.transform.position == axeTempHolder.transform.position) { axeState = AxeState.Thrown; } if (Input.GetButtonDown("Y") && axe.transform.position != axeTempHolder.transform.position) { startPos = axe.transform.position; startTime = Time.time; journeyLength = Vector3.Distance(startPos, endPos); axeState = AxeState.Returning; } if (axeState == AxeState.Thrown) { ThrownAxeWithPhysics(); } if (axeState == AxeState.Travelling || axeState == AxeState.Returning) { axe.transform.Rotate(6.0f * axeRotationSpeed * Time.deltaTime, 0, 0); } if (axeState == AxeState.Returning) { axeCollsions.NoCollision(1); RecallAxe(); } else if (axeState != AxeState.Returning) { axeCollsions.NoCollision(0); } } }
// Throw Axe with Physics called when the axe is actually thrown void ThrowAxeWithPhysics() { // make sure that the axe does not have a parent, if we don't do this then the axe will still move around // while the player looks around axe.transform.parent = null; // lets change up the state of the axe axeState = AxeState.Travelling; // WE need to change the values of iskinematic and usegravity axeRB.isKinematic = false; axeRB.useGravity = true; // finally let's throw the axe using physics. axeRB.AddForce(axe.transform.forward * axeThrowPower); }
void RecalledAxe() { axeState = AxeState.Static; axeCollsions.RemoveConstraints(); axe.transform.position = axeTempHolder.transform.position; axe.transform.rotation = axeTempHolder.transform.rotation; axeRb.isKinematic = true; axeRb.useGravity = false; axe.transform.parent = this.transform; isCameraShaking = true; Invoke("CameraShake", ShakeSeconds); Camera.main.transform.DOComplete(); Camera.main.transform.DOShakePosition(.2f, .9f, 25, 90, false, true); }
public void OnAxeMonsterCollided() { if (axeState == AxeState.Returning) { return; } if (rb != null) { rb.useGravity = false; rb.isKinematic = true; } axeState = AxeState.Grabbled; }
// Occurs when the axe has been recalled. void RecalledAxe() { // We need to change the current state of our axe back to static axeState = AxeState.Static; // We want to remove the position constraints from the rigidbody axeCollisions.RemoveConstraints(); // We want to complete a hard reset of the position and rotation of the axe back to the initial settings axe.transform.position = axeTempHolder.transform.position; axe.transform.rotation = axeTempHolder.transform.rotation; // Change iskinematic and usegravity axeRB.isKinematic = true; axeRB.useGravity = false; // change up the parent of the axe so that it is back under the main camera. axe.transform.parent = this.transform; }
public override void GrabBegin(OVRGrabber hand, Collider grabPoint) { m_grabbedBy = hand; m_grabbedCollider = grabPoint; rb.isKinematic = true; rb.useGravity = false; if (isFirstGrab) { isFirstGrab = false; OnFirstGrabBegin.Invoke(); } axeMeshTransform.rotation = new Quaternion(0, 0, 0, 0); isAvailableToReturn = false; axeState = AxeState.Static; }
public void OnAxeCollided() { if (gameObject.activeInHierarchy) { if (axeState == AxeState.Returning) { return; } if (rb != null) { rb.useGravity = false; rb.isKinematic = true; } axeState = AxeState.Thrown; } }
// Now we need to change update to fixedupdate and start filling out our script. void FixedUpdate() { // Ok the first thing that we want to setup is a check to see if we left click which will be used to throw the axe for now we are just // going to change the state of the axe to thrown if (Input.GetMouseButtonDown(0)) { axeState = AxeState.Thrown; } // Now let's setup the right mouse click to recall the axe, if (Input.GetMouseButtonDown(1)) { // First of all we need to get some positions for our lerping function like the starting and ending positions startPos = axe.transform.position; endPos = axeTempHolder.transform.position; // We need to reset our startTime to Time.time startTime = Time.time; // Our journey length will be a distance check from the start position to the end position journeyLength = Vector3.Distance(startPos, endPos); // Finally we need to change up the axe's state. axeState = AxeState.Returning; } // Ok, we want to check to see if our axe has been thrown and if so we are going to call a function, which we will setup in a minute if (axeState == AxeState.Thrown) { ThrowAxeWithPhysics(); } // Next let's check to see if the axe is travelling or returning and if so, we want to make the axe spin. if (axeState == AxeState.Travelling || axeState == AxeState.Returning) { axe.transform.Rotate(6.0f * axeRotationSpeed * Time.deltaTime, 0, 0); } // Ok and finally, if the axe is supposed to return then we need to call another function. if (axeState == AxeState.Returning) { RecallAxe(); } }
public void CollisionOccured() { axeState = AxeState.Static; }
public Axe(Rectangle position, AxeState state, double scale, Level level) : base(position, true, scale, level) { this.state = state; textures = LoadTextures <AxeState>(0); }