- Home /
Different Touch iOS work fine/Android problem
Hi All,
I have a code for move a cube around my screen, I have this code
public float speed;
public float Maxspeed;
private Vector3 pos;
private Vector2 previousPos;
void Start()
{
previousPos = transform.position;
}
void FixedUpdate ()
{
MoveCube();
previousPos = transform.position;
}
void MoveCube()
{
if(GameController.instance.StartGame)
{
Ray ray;
RaycastHit hit;
if(Input.touchCount == 1)
{
Touch touch = Input.GetTouch(0);
ray = Camera.main.ScreenPointToRay(touch.position);
if(Input.GetTouch(0).phase == TouchPhase.Moved)
{
if(Physics.Raycast(ray,out hit,100))
{
pos = Input.GetTouch(0).deltaPosition * speed;
//rigidbody.MovePosition(pos + transform.position);
rigidbody.velocity = Vector3.ClampMagnitude(pos,Maxspeed);
}
}else if (Input.GetTouch(0).phase == TouchPhase.Stationary || Input.GetTouch(0).phase == TouchPhase.Canceled || Input.GetTouch(0).phase == TouchPhase.Ended)
{
rigidbody.velocity = Vector3.zero;
}
}
}else
{
rigidbody.velocity = Vector3.zero;
}
}
This code work fine on iOS, but on Android, the cube move slow and "jumping".
Any help?
Answer by zharik86 · Feb 17, 2015 at 07:51 AM
Replace your move code from FixedUpdate to Update:
void Update () {
MoveCube();
previousPos = transform.position;
}
It's working. I hope that it will help you.
@$$anonymous$$agicFrame You change only velocity of rigidbody. Try move your code in Update function. If it's not work, you can use touch events in Update(), but change velocity in FixedUpdate() by variable of touch event from Update().
Your answer
Follow this Question
Related Questions
Unity 2D Mobile Game Drawing Mechanic 0 Answers
How do you map touch to one of the input axes? 1 Answer
How to centre a 3D pinch zoom 1 Answer
Different animations on mobile 0 Answers
How to detect screen touching more frequently than fps. 1 Answer