private void FixedUpdate() { if (m_drive == true) { //pass input to ship float h = CrossPlatformInputManager.GetAxis("Horizontal"); float v = CrossPlatformInputManager.GetAxis("Vertical"); m_ship.Move(h, v); bool s = CrossPlatformInputManager.GetButtonDown("Jump"); m_ship.PowerUp(s); } else { m_ship.m_RB.velocity = new Vector3(0, 0, 0); } }
private void FixedUpdate() { //updating target updateWaypoint(); m_target = m_waypointList[m_currentPt].transform; Debug.DrawLine(transform.position, m_target.position); //otherwise drive //else if (m_drive == true) { float accel = 0; //amount to accelerate float steer = 0; //amount to steer //direction to turn Vector3 dir = (m_target.position - transform.position).normalized; float direction = Vector3.Dot(dir, m_ship.transform.right); //turn by direction amount steer += m_steerSensitivity * direction * 2; //accelerate based on how close to racing line accel = 1 - Mathf.Abs(direction); if (direction > 0.5f || direction < -0.5f) { accel *= -1; } Mathf.Clamp(accel, -1.0f, 1.0f); Mathf.Clamp(steer, -1.0f, 1.0f); Debug.Log("A: " + accel + " S: " + steer + " D: " + direction); m_ship.Move(steer, accel); //USING POWERUPS //if rocket if (m_ship.m_properties.playerState == PlayerProperties.PlayerState.shipRocket) { Ray ray = new Ray(transform.position, transform.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit, 30f)) { if (hit.collider.gameObject.tag == "Player" || hit.collider.gameObject.tag == "Enemy") { m_ship.PowerUp(true);//(1); } } } //if trap depending on random value, do 1 of 2 tactics (decided on awake) if (m_ship.m_properties.playerState == PlayerProperties.PlayerState.shipTrap) { //drop on top of pick up if (m_rand < 0.5) { m_ship.PowerUp(true);//(1); } //drop if somebody is behind within a certain distance if (m_rand >= 0.5) { Ray ray = new Ray(transform.position, -transform.forward); RaycastHit hit; if (Physics.Raycast(ray, out hit, 10f)) { if (hit.collider.gameObject.tag == "Player" || hit.collider.gameObject.tag == "Enemy") { m_ship.PowerUp(true);//(1); } } } } } //if not set to drive, stay still else // (m_drive == false)// || m_target == null) { m_ship.Move(0, 0); m_RB.velocity = new Vector3(0, 0, 0); } }