void FixedUpdate() { // float moveHorizontal = Input.GetAxis ("Horizontal"); // float moveVertical = Input.GetAxis ("Vertical"); // Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical); // Vector3 accelerationRaw = Input.acceleration; // Vector3 acceleration = FixAcceleration (accelerationRaw); // Vector3 movement = new Vector3 (acceleration.x, 0.0f, acceleration.y); Vector2 direction = touchPad.GetDirection(); Vector3 movement = new Vector3(direction.x, 0.0f, direction.y); rb.velocity = movement * speed; rb.position = new Vector3 ( Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax) ); rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt); }
void FixedUpdate() { Vector2 direction = touchPad.GetDirection(); Vector2 pointerPosition = touchPad.GetPointerPosition(); if (touchPad.HasGotFirstTouch()) { pointerPosition = Camera.main.ScreenToWorldPoint(pointerPosition); } else { pointerPosition.x = 0; } Vector3 movement = new Vector3(((pointerPosition.x) - (gameObject.transform.position.x)), direction.y, 0); GetComponent <Rigidbody>().velocity = (movement * speed); GetComponent <Rigidbody>().position = new Vector3 ( Mathf.Clamp(GetComponent <Rigidbody>().position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(GetComponent <Rigidbody>().position.z, boundary.zMin, boundary.zMax) ); //robotMesh.transform.rotation = Quaternion.Euler(90f, GetComponent<Rigidbody>().velocity.x * (-tilt), GetComponent<Rigidbody>().velocity.x); robotMesh.transform.localRotation = Quaternion.Euler(0, GetComponent <Rigidbody>().velocity.x *(-tilt), 0); }
void FixedUpdate() { float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveHorizontal, 0f, moveVertical); if (Application.platform == RuntimePlatform.Android) { //Vector3 acceleration = Input.acceleration; //Vector3 fixedAcceleration = FixAcceleration(acceleration); //movement = new Vector3(fixedAcceleration.x, 0f, fixedAcceleration.y); Vector2 direction = touchPad.GetDirection(); movement = new Vector3(direction.x, 0f, direction.y); } playerRigidbody.velocity = movement * speed; playerRigidbody.position = new Vector3( Mathf.Clamp(playerRigidbody.position.x, boundary.xMin, boundary.xMax), 0f, Mathf.Clamp(playerRigidbody.position.z, boundary.zMin, boundary.zMax) ); playerRigidbody.rotation = Quaternion.Euler(0f, 0f, playerRigidbody.velocity.x * -tilt); }
void FixedUpdate() { #if UNITY_IOS Vector2 direction = touchPad.GetDirection(); Vector3 movement = new Vector3(direction.x, 0.0f, direction.y); #else float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); #endif rb.velocity = movement * speed; rb.position = new Vector3 ( Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax) ); rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt); }
private void FixedUpdate() { //float moveHorizontal = Input.GetAxis("Horizontal"); //float moveVertical = Input.GetAxis("Vertical"); //get movement entered //Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); //for webdev //Vector3 accelerationRaw = Input.acceleration; //line and function added for comfort in how you're initially holding your phone //Vector3 acceleration = FixAcceleration(accelerationRaw); Vector2 direction = touchPad.GetDirection(); Vector3 movement = new Vector3(direction.x, 0.0f, direction.y); Rigidbody ship = GetComponent <Rigidbody>(); //move ship ship.velocity = movement * speed; //clamp the player inside the screen ship.position = new Vector3 ( Mathf.Clamp(ship.position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(ship.position.z, boundary.zMin, boundary.zMax) ); ship.rotation = Quaternion.Euler(0.0f, 0.0f, ship.velocity.x * -tilt); }
private void FixedUpdate() { #if (USE_TILT) Vector3 accelerationRaw = Input.acceleration; Vector3 acceleration = FixAcceleration(accelerationRaw); Vector3 movement = new Vector3(acceleration.x, 0.0f, acceleration.y); #elif (USE_TOUCHPAD) Vector2 direction = touchPad.GetDirection(); Vector3 movement = new Vector3(direction.x, 0.0f, direction.y); #else float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); #endif Rigidbody rb = GetComponent <Rigidbody>(); rb.velocity = movement * speed; rb.position = new Vector3 ( Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax) ); rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt); }
private void FixedUpdate() { /**PC Control**/ /* * float moveHorizontal = Input.GetAxis("Horizontal"); * float moveVertical = Input.GetAxis("Vertical"); * * Vector3 movement = new Vector3(moveHorizontal, 0f, moveVertical); */ Vector2 direction = Vector2.zero; if (gameObject.activeSelf) { direction = touchPad.GetDirection(); } Vector3 movement = new Vector3(direction.x, 0f, direction.y); rb.velocity = movement * speed; rb.MoveRotation(Quaternion.Euler(0f, 0f, rb.velocity.x * -tilt)); rb.position = new Vector3( Mathf.Clamp(rb.position.x, -GameController.xAxis, GameController.xAxis), 0f, Mathf.Clamp(rb.position.z, -GameController.zAxis, GameController.zAxis) ); }
void FixedUpdate() { Vector3 movement; if (IsMobile == true) { Vector2 direction = touchPad.GetDirection(); movement = new Vector3(direction.x, 0.0f, direction.y); //Vector3 acceleration = FixAcceleration (Input.acceleration); //movement = new Vector3 (acceleration.x, 0.0f, acceleration.y); } else { float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); movement = new Vector3(moveHorizontal, 0.0f, moveVertical); } //Vector2 direction = touchPad.GetDirection (); //Vector3 movement = new Vector3 (direction.x, 0.0f, direction.y); rb.velocity = movement * Speed; rb.position = new Vector3 ( Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax), 0, Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax) ); rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -SideTilt); }
void FixedUpdate() { weapon2Counter = weapon2Counter + 1; Vector3 movement = new Vector3(0.0f, 0.0f, 0.0f); if (settingsHolder.mode == 0) { Vector2 direction = touchPad.GetDirection(); movement = new Vector3(direction.x, 0.0f, direction.y); } else if (settingsHolder.mode == 1) { Vector3 accelerationRaw = Input.acceleration; Vector3 acceleration = FixAcceleration(accelerationRaw) * settingsHolder.sensibiliteAccelerometre; movement = new Vector3(acceleration.x, 0.0f, acceleration.y); } rigidbody.velocity = movement * speed; rigidbody.position = new Vector3 ( Mathf.Clamp(rigidbody.position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(rigidbody.position.z, boundary.zMin, boundary.zMax) ); rigidbody.rotation = Quaternion.Euler(0.0f, 0.0f, rigidbody.velocity.x * -tilt); }
void FixedUpdate() { #if UNITY_STANDALONE || UNITY_WEBGL float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); #endif //Motion Controls //Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); //Vector3 accelerationRaw = Input.acceleration; //Vector3 acceleration = FixAcceleration(accelerationRaw); #if UNITY_IOS //Touch Controls Vector2 direction = touchPad.GetDirection(); Vector3 movement = new Vector3(direction.x, 0.0f, direction.y); #endif GetComponent <Rigidbody>().velocity = movement * speed; GetComponent <Rigidbody>().position = new Vector3( Mathf.Clamp(GetComponent <Rigidbody>().position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(GetComponent <Rigidbody>().position.z, boundary.zMin, boundary.zMax) ); GetComponent <Rigidbody>().rotation = Quaternion.Euler(0.0f, 0.0f, GetComponent <Rigidbody>().velocity.x * -tilt); }
private void FixedUpdate() { //каждый кадр получаем положение телефона в пространстве //Vector3 accelerationRaw = Input.acceleration; //получаем координаты текущего положения телефона относительно стартового положения //Vector3 acceleration = FixAcceleration(accelerationRaw); Vector2 direction = touchPad.GetDirection(); //float moveHorizontal = Input.GetAxis("Horizontal"); //float moveVertical = Input.GetAxis("Vertical"); rigidbody.rotation = Quaternion.Euler(0f, 0f, rigidbody.velocity.x * -tilt); //rigidbody.velocity = new Vector3(moveHorizontal, 0, moveVertical) * speed; //rigidbody.velocity = new Vector3(acceleration.x, 0, acceleration.y) * speed; rigidbody.velocity = new Vector3(direction.x, 0, direction.y) * speed; rigidbody.position = new Vector3 ( Mathf.Clamp(rigidbody.position.x, boundary.xMin, boundary.xMax), 0f, Mathf.Clamp(rigidbody.position.z, boundary.zMin, boundary.zMax) ); }
void FixedUpdate() { Vector2 direction = touchPad.GetDirection(); float translation = direction.y * speed; if (currentTranslation != translation) { currentTranslation = translation; transform.RotateAround(point, new Vector3(0.0f, 1.0f, 0.0f), 5.0f * (direction.y >= 0.0f ? 1.0f : -1.0f)); } }
private void FixedUpdate() { Vector2 direction = touchPad.GetDirection(); float num = direction.y * speed; if (currentTranslation != num) { currentTranslation = num; base.transform.RotateAround(point, new Vector3(0f, 1f, 0f), 5f * ((!(direction.y >= 0f)) ? (-1f) : 1f)); } }
void FixedUpdate() { // float moveHorizontal = Input.GetAxis("Horizontal"); // float moveVertical = Input.GetAxis("Vertical"); float moveHorizontal = simpleTouchPad.GetDirection().x; float moveVertical = simpleTouchPad.GetDirection().y; Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical); rigidbody.velocity = movement * speed; rigidbody.position = new Vector3( Mathf.Clamp(rigidbody.position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(rigidbody.position.z, boundary.zMin, boundary.zMax) ); rigidbody.rotation = Quaternion.Euler(0.0f, 0.0f, rigidbody.velocity.x * -tilt); }
void FixedUpdate() { //float rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX; //float rotationX = transform.localEulerAngles.y + movement.x * sensitivityX; Vector2 direction = _simpleTouchPad.GetDirection(); float rotationX = transform.localEulerAngles.y + direction.x * sensitivityX; rotationX = ClampAngle(rotationX, minimumX, maximumX); transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, rotationX, 0); //transform.Rotate(0,Input.GetAxis("Mouse X") * sensitivityX,0); }
private float getHorizontalMovement() { float horizontalMovement = rigidBody.velocity.x; float xAxis = 0f; #if UNITY_ANDROID xAxis = movementTouchPad.GetDirection().x; #else xAxis = Input.GetAxis("Horizontal"); #endif if (enoughAxis(xAxis, MIN_HORIZONTAL_AXIS)) { horizontalMovement = xAxis * xVelocity; } return(horizontalMovement); }
void FixedUpdate() { // float moveHorizontal = Input.GetAxis ("Horizontal"); //float moveVertical = Input.GetAxis ("Vertical"); Vector2 direction = touchPad.GetDirection(); Vector3 movement = new Vector3(direction.x, 0.0f, direction.y); GetComponent <Rigidbody>().velocity = movement * speed; GetComponent <Rigidbody>().position = new Vector3 ( Mathf.Clamp(GetComponent <Rigidbody>().position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(GetComponent <Rigidbody>().position.z, boundary.zMin, boundary.zMax) ); GetComponent <Rigidbody>().rotation = Quaternion.Euler(0.0f, 0.0f, GetComponent <Rigidbody>().velocity.x * -tilt); }
void FixedUpdate() { Vector3 accelerationRaw = Input.acceleration; Vector3 acceleration = FixAcceleration(accelerationRaw); Vector2 direction = touchPad.GetDirection(); Vector3 movement = new Vector3(direction.x, 0.0f, direction.y); rb.velocity = movement * speed; rb.position = new Vector3 ( Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax) ); rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt); }
private void FixedUpdate() { // float moveHorizontal = Input.GetAxis("Horizontal"); // float moveVertical = Input.GetAxis("Vertical"); //_rigidbody.velocity = new Vector3(moveHorizontal,0f, moveVertical) * speed; // Vector3 acceleration = FixAcceleration(Input.acceleration); // _rigidbody.velocity = new Vector3(acceleration.x,0f, acceleration.y) * speed; Vector2 direction = touchPad.GetDirection(); _rigidbody.velocity = new Vector3(direction.x, 0f, direction.y) * speed; _rigidbody.position = new Vector3( Mathf.Clamp(_rigidbody.position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(_rigidbody.position.z, boundary.zMin, boundary.zMax) ); _rigidbody.rotation = Quaternion.Euler(0.0f, 0.0f, _rigidbody.velocity.x * -tilt); }
void InputMovement() { moveHorizontal = Input.GetAxis("Horizontal"); moveVertical = Input.GetAxis("Vertical"); movement = new Vector3(moveHorizontal, 0.0f, moveVertical); if (myRb != null) { myRb.AddForce(movement * speed); direction = stp.GetDirection(); movement = new Vector3(direction.x, 0.0f, direction.y); myRb.AddForce(movement * speed); } if (playerFlare != null) { playerFlare.transform.position = transform.position; } }
void FixedUpdate() { //if (!isLocalPlayer) { // return; //} //float moveHorizontal = Input.GetAxis ("Horizontal"); //float moveVertical = Input.GetAxis ("Vertical"); Vector2 direction = touchPad.GetDirection(); Vector3 movement = new Vector3(direction.x, 0.0f, direction.y); rb.velocity = movement * speed; rb.position = new Vector3( Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax) ); rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt); }
// FixedUpdate is called once per frame for physics void FixedUpdate() { // Translation Vector3 movement = new Vector3(); #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER // PC float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); movement = new Vector3(moveHorizontal, 0f, moveVertical); #elif UNITY_IOS || UNITY_ANDROID // MOBILE if (m_controlType == ControlType.Accelerometer) { // Accelerometer Vector3 accelerationRaw = Input.acceleration; Vector3 acceleration = FixAcceleration(accelerationRaw); movement = new Vector3(acceleration.x, 0f, acceleration.y); } else { // touchPad Vector2 direction = m_touchPad.GetDirection(); movement = new Vector3(direction.x, 0f, direction.y); } #endif // Speed m_rb.velocity = movement * m_speed; // Clamp to Boundary m_rb.position = new Vector3( Mathf.Clamp(m_rb.position.x, m_boundary.xMin, m_boundary.xMax), 0f, Mathf.Clamp(m_rb.position.z, m_boundary.zMin, m_boundary.zMax) ); // Rotation m_rb.rotation = Quaternion.Euler(0f, 0f, -m_tilt * m_rb.velocity.x); }
void FixedUpdate() { // float moveHorizontal = Input.GetAxis ("Horizontal"); // float moveVertical = Input.GetAxis ("Vertical"); // Vector3 movement = new Vector3 (moveHorizontal,0.0f,moveVertical); Vector2 direction = touchPad.GetDirection(); Vector3 movement = new Vector3(direction.x, 0.0f, direction.y); rb.velocity = movement * speed; var minX = Camera.main.ScreenToWorldPoint(new Vector2(0.1f * Screen.width, 0)).x; var maxX = Camera.main.ScreenToWorldPoint(new Vector2(0.9f * Screen.width, 0)).x; rb.position = new Vector3 ( Mathf.Clamp(rb.position.x, minX, maxX), 0.0f, Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax) ); rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt); Debug.Log(rb.velocity.x); }
private void FixedUpdate() { //desktop if (SystemInfo.deviceType == DeviceType.Desktop) { float moveHorizontal = Input.GetAxis("Horizontal"); float moveVertical = Input.GetAxis("Vertical"); _rigid.velocity = new Vector3(moveHorizontal, 0, moveVertical) * Speed; } else { //mobile //Vector3 acceleration = FixAcceleration(Input.acceleration); //_rigid.velocity = new Vector3(acceleration.x, 0, acceleration.y) * Speed; Vector2 direction = TouchPad.GetDirection(); _rigid.velocity = new Vector3(direction.x, 0, direction.y) * Speed; } _rigid.position = new Vector3(Mathf.Clamp(_rigid.position.x, Boundary.XMin, Boundary.XMax), 0, Mathf.Clamp(_rigid.position.z, Boundary.ZMin, Boundary.ZMax)); _rigid.rotation = Quaternion.Euler(0, 0, _rigid.velocity.x * -Tilt); }
/** * Called after each physic step **/ void FixedUpdate() { //Debug.Log("FixedUpdate time :" + Time.deltaTime); /////////////////////////////////////////////////////////////// // // /* // * Move the player using keyboard // */ // // // Get the player's input // float moveHorizontal = Input.GetAxis ("Horizontal"); // float moveVertical = Input.GetAxis ("Vertical"); // // // Created the vector that holds the player's movement // Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical); /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// // // /* // * Move the player using accelerometer // */ // // Get the accelerometer input with no changes // Vector3 accelerationRaw = Input.acceleration; // Vector3 acceleration = FixAcceleration(accelerationRaw); // //Debug.Log (acceleration.x + "," + acceleration.y + "," + acceleration.z); // // /* // * Created the vector that holds the player's movement. // * // * In the device, there is x (horizontal) e y (vertical). But in unity, // * our project is x (horizontal) e z (vertical). Thus, z, in the project, // * must be y in the device. // */ // Vector3 movement = new Vector3 (acceleration.x, 0.0f, acceleration.y); // /////////////////////////////////////////////////////////////// /* * Move the player using touchscreen */ Vector2 direction = touchPad.GetDirection(); /* * Created the vector that holds the player's movement. */ Vector3 movement = new Vector3(direction.x, 0.0f, direction.y); /* * Aplly the input into rigidbody as the velocity * * Input is between 0 and 1, at the maximum 1 unity, so multiply the movement per speed. */ rb.velocity = movement * speed; /* * Before render the next frame, will check the position, to avoid the player go outside the game area. * * The position will be set inside game area if the position would be outside the game area. */ rb.position = new Vector3( Mathf.Clamp(rb.position.x, boundary.xMin, boundary.xMax), 0.0f, Mathf.Clamp(rb.position.z, boundary.zMin, boundary.zMax) ); /* * Tilts the player while moviment left to right, Z axis. * * The rotation is on the Z axis, but the movement is along X axis. * * The '-tilt' is to tilt in the correct direction. */ rb.rotation = Quaternion.Euler(0.0f, 0.0f, rb.velocity.x * -tilt); // Testing rotating in X axis too //rb.rotation = Quaternion.Euler (rb.velocity.z * tilt, 0.0f, rb.velocity.x * -tilt); }
private Vector2 TouchDirection() { return(simpleTouchPad.GetDirection()); }