- Home /
Unity virtual joystick - jarring movement
I'm creating an infinite flyer game in which you control the plane using a mobile joystick. There are two control one to rotate the plane up/down/left/right and the other to move the plane up/down/left/right. While rotating the plane there is a lot of jarring that happens but doens't happen while moving it. Here is the code in the move script:
public class move : MonoBehaviour
{
public Joystick joystick;
public Joystick joystick1;
float rotateVertical;
float rotateHorizontal;
public float sensitivity;
Quaternion _initialRotation;
float _pitch, _yaw;
float moveHorizontal;
float moveVertical;
void Start()
{
_initialRotation = transform.rotation;
}
void Update()
{
_pitch = _pitch + joystick.Vertical * sensitivity;
_yaw = _yaw - joystick.Horizontal * sensitivity;
transform.rotation = _initialRotation * Quaternion.Euler(_pitch*Time.deltaTime,-_yaw*Time.deltaTime, 0) ;
transform.Translate(moveHorizontal * Time.deltaTime, moveVertical * Time.deltaTime, 0);
}
}
When I set the sensitivity to values like .5 or 1, then there is no jarring movement. However anything above that leads to a lot of jarring. There is also a camerafollow script attached.
[SerializeField] Transform target;
public Vector3 defaultDist = new Vector3(0f, 0, 7.5f);
[SerializeField] float distDamp = .1f;
public Vector3 velocity = Vector3.one;
Transform myT;
void Awake()
{
myT = transform;
}
void LateUpdate()
{
SmoothFollow();
}
void SmoothFollow()
{
Vector3 toPos = target.position + (target.rotation * defaultDist);
Vector3 curPos = Vector3.SmoothDamp(myT.position, toPos,ref velocity ,distDamp);
myT.position = curPos ;
myT.LookAt(target, target.up);
}
Your answer
Follow this Question
Related Questions
Detect maximum upper area of joystick? 0 Answers
How can I rotate my player to look at the direction my Joystick is pointing to? (Top-Down 2D) 0 Answers
Input.GetJoystickNames returns empty strings in Unity 5 (mac)? 0 Answers
Joystick isn't recognize by Unity when i activate CardBoard option 0 Answers
How to detect Double Clicking Horizontal/Vertical Axis on joystick 0 Answers