// Update is called once per frame void Update() { if (touchAxisControl.IsTouching()) { m_TargetXY = new Vector3(Mathf.Clamp(ship.localPosition.x + touchAxisControl.GetAxis("Horizontal"), -xRange, xRange), Mathf.Clamp(ship.localPosition.y + touchAxisControl.GetAxis("Vertical"), -yRange, yRange)); } Vector2 lerpPos = Vector2.Lerp(new Vector2(ship.localPosition.x, ship.localPosition.y), m_TargetXY, snapSpeed); ship.localEulerAngles = new Vector3(Remap(ship.localPosition.y - m_TargetXY.y, -1, 1, -Mathf.Abs(pitchAndRollRange.x), Mathf.Abs(pitchAndRollRange.x)), ship.localEulerAngles.y, Remap(ship.localPosition.x - m_TargetXY.x, -1, 1, -Mathf.Abs(pitchAndRollRange.y), Mathf.Abs(pitchAndRollRange.y))); ship.localPosition = new Vector3(lerpPos.x, lerpPos.y, ship.localPosition.z); }
void Update() { if (m_TouchControl.IsTouching()) { // Get the joystick value Vector3 val = Wrj.Utils.ToVector3(m_TouchControl.GetAxis()); // The line/arrow position is inverted to point the direction the ball will be shot. It's doubled for improved visibility. Vector3 pos2 = transform.position + val * -2f; // Invert the force and save it globally so it's up-to-date upon untouch. Will be used as the basis of desired velocity. m_Force = -val; // Draw the indicator arrow m_Line.positionCount = 2; m_Line.SetPosition(0, transform.position); m_Line.SetPosition(1, pos2); } }
// Update is called once per frame void Update() { if (touchAxisControl.IsTouching()) { if (!m_bHasBeenTouching) { m_bHasBeenTouching = true; m_InitialXY = new Vector2(ship.localPosition.x, ship.localPosition.y); } m_TargetXY = new Vector3(Mathf.Clamp(m_InitialXY.x + touchAxisControl.GetAxis("Horizontal") * xRange, -xRange, xRange), Mathf.Clamp(m_InitialXY.y + touchAxisControl.GetAxis("Vertical") * yRange, -yRange, yRange)); } else { m_bHasBeenTouching = false; } Vector2 lerpPos = Vector2.Lerp(new Vector2(ship.localPosition.x, ship.localPosition.y), m_TargetXY, snapSpeed); ship.localEulerAngles = new Vector3(Remap(ship.localPosition.y - m_TargetXY.y, -yRange, yRange, -30, 30), ship.localEulerAngles.y, Remap(ship.localPosition.x - m_TargetXY.x, -xRange, xRange, -90, 90)); ship.localPosition = new Vector3(lerpPos.x, lerpPos.y, ship.localPosition.z); }