Hi all,
I have struggling to move the player ball in the following grid based map. I tried rigidbody addForce and transform.Translate but nothing worked.
void FixedUpdate()
{
if (Input.GetKey(KeyCode.LeftArrow))
{
int indicator = PlayerPrefs.GetInt("indicator", 0);
if(indicator == 1)
{
turn = true;
m_Rigidbody.AddForce(direction * 0);
direction = Vector3.left;
m_Rigidbody.AddForce(direction * m_Speed);
turn = false;
}
}
if (Input.GetKey(KeyCode.RightArrow))
{
int indicator = PlayerPrefs.GetInt("indicator", 0);
if (indicator == 1)
{
turn = true;
m_Rigidbody.AddForce(direction * 0);
direction = Vector3.right;
m_Rigidbody.AddForce(direction * m_Speed);
turn = false;
}
}
if (!turn)
{
m_Rigidbody.AddForce(direction * m_Speed);
}
}
Green color sphere is my player object. I want player to continuously move forward (first in +z axis). Then when the user press left or right arrow keys, i want the ball to turn left or right and continue in that direction.

