I want to publish my game for apple tv. My game contains two types of player movement but at present nothing running via tv remote. I can’t able to move my player using remote control. Same code words perfectly work for iOS version of game.
My first player movement code using touch:
void Update ()
{
MoveBirdOnXAxis ();
if (Input.GetMouseButtonDown (0))
swatAreaDetected = IsSwatTouchArea ();
else if (Input.GetMouseButton (0) && !swatAreaDetected) {
flameObj.SetActive (true);
BoostOnYAxis ();
} else if (Input.GetMouseButtonUp (0)) {
flameObj.SetActive (false);
swatAreaDetected = false;
}
FixBabyGrayRotation ();
}
private bool IsSwatTouchArea ()
{
Vector3 pos = Camera.main.ScreenToWorldPoint (Input.mousePosition);
RaycastHit2D hit = Physics2D.Raycast (pos, Vector2.zero);
if (hit != null && hit.collider != null && hit.collider.CompareTag (GameConstants.TAG_SWAT_TOUCH_AREA))
return true;
return false;
}
void MoveBirdOnXAxis ()
{
// transform.position += new Vector3 (Time.deltaTime * horzSpeed, 0, 0);
Vector2 currVelocity = myRigidBody.velocity;
currVelocity.x = horzSpeed;
myRigidBody.velocity = currVelocity;
}
void BoostOnYAxis ()
{
Vector2 currVelocity = myRigidBody.velocity;
currVelocity.y = velPerJump;
myRigidBody.velocity = currVelocity;
// myRigidBody.velocity = new Vector2 (0, velPerJump);
}
My second player movement code using accelerometer:
void Start ()
{
initalAccel = Input.acceleration;
}
void Update ()
{
FixBuddyRotation ();
}
void FixedUpdate ()
{
Vector3 accel = (Input.acceleration - initalAccel);
Vector2 appliedAccelVel = new Vector2 (accel.x, -accel.z);
if (Mathf.Abs (accel.x) > horzEliminationValue)
appliedAccelVel.x = horzSpeed * Mathf.Sign (appliedAccelVel.x);
else
appliedAccelVel.x = myRigidBody.velocity.x * 0.6f;
if (Mathf.Abs (accel.z) > vertEliminationValue)
appliedAccelVel.y = vertSpeed * Mathf.Sign (appliedAccelVel.y);
else
appliedAccelVel.y = myRigidBody.velocity.y * 0.6f;
if (appliedAccelVel.x < 0f && applyBackwardThrust) {
applyBackwardThrust = false;
appliedAccelVel.y = 0;
appliedAccelVel.x *= 1.5f;
Vector3 currVel = myRigidBody.velocity;
currVel.y = 0;
myRigidBody.velocity = Vector2.Lerp (currVel, appliedAccelVel, 1f);
} else
myRigidBody.velocity = Vector2.Lerp (myRigidBody.velocity, appliedAccelVel, Time.deltaTime * 5f);
if (appliedAccelVel.x > 0f)
applyBackwardThrust = true;
}
Above two are different approaches, but none of above is working. Via remote I can’t able to move players. So what changes I need to do in above so that I can able to move my players.