Hi,
I have problem with tilting on Android which should move with the object. Here is simple code:
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
if (isAI)
{
AIControl();
}
else
{
PlayerControl();
}
}
private void PlayerControl()
{
#if UNITY_PLATFORM_ANDROID
playerMove = new Vector2(0, Mathf.Sign(Input.acceleration.y));
#else
playerMove = new Vector2(0, Input.GetAxisRaw("Vertical"));
#endif
}
private void AIControl()
{
if (ball.transform.position.y > transform.position.y + 0.5f)
{
playerMove = new Vector2(0, 1);
}
else if (ball.transform.position.y < transform.position.y - 0.5f)
{
playerMove = new Vector2(0, -1);
}
else
{
playerMove = new Vector2(0, 0);
}
}
private void FixedUpdate()
{
rb.velocity = playerMove * movementSpeed;
}
On Windows is everything fine, code is working. Do you have any idea what’s wrong?
Thanks, Peter