Hello!
Basically I’d like to get the touch joystick controller on the screen to follow the players touch if they move out of it’s bounds. I figure I’d just, each frame, move it a bit if the finger is out of bounds. but I’m not sure how to actually find the position required.
Anyone who remembers Geometry and Trig know the answer? THANK YOU!!!
Please forgive this code – It was created with the help of someone who was much smarter than me and may be very, very ugly!
joystickTouchPos = Input.mousePosition;
screenPosJoystickM = Vector3(joystickTouchPos.x, joystickTouchPos.y, 20);
worldPosJoystickM = guiCamera.ScreenToWorldPoint(screenPosJoystickM);
joystickCenterX = JoystickObject.transform.position.x;
joystickCenterY = JoystickObject.transform.position.y;
currentTouchX = worldPosJoystickM.x;
currentTouchY = worldPosJoystickM.y;
varcenterJoystickM = Vector2(joystickCenterX, joystickCenterY);
varcurrentJoystickM = Vector2(currentTouchX, currentTouchY);
vardistJoystickM = Vector2.Distance(centerJoystickM, currentJoystickM);
if (largeScreen)
{
distJoystickM = distJoystickM * 2;
}
varhorJoystickM = currentTouchX - joystickCenterX;
varverJoystickM = currentTouchY - joystickCenterY;
moveX = currentTouchX - joystickCenterX;
moveY = currentTouchY - joystickCenterY;
varangleJoystickM : float = Mathf.Atan2(moveX, moveY) * Mathf.Rad2Deg;
distJoystickM = distJoystickM * 1.33;
//DoCircleMovementHere
if (distJoystickM > 4.0)
{
}
distJoystickM = Mathf.Clamp(distJoystickM, 0, 4);
if (GetComponent(joystick).isNotAttacking)
{
playerObject.GetComponent(playerScript).angle = angleJoystickM + mainCamera.GetComponent(SmoothFollow).angleOffsetX;
playerObject.GetComponent(playerScript).moveSpeed = distJoystickM;
}