- Home /
Question by
SuleymanO · Oct 04, 2014 at 04:56 AM ·
c#touch controlsspace shooter
Touch movement - freedrag jittery with tilt from spaceshooter
ok guys, ive got my touch controls working at the moment, but unfortunately its a little bit jittery, i find if the user moves really slowly its really responsive, however if you move quickly around the screen, its much slower to move around, i think maybe the normalize is causing it but i couldnt find a better solution(im new to coding)
speed is a float variable set in my GameController
`void FixedUpdate ()
{
float moveHorizontal;
float moveVertical;
moveHorizontal = Input.GetAxis ("Horizontal");
moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal,moveVertical, 0.0f);
rigidbody.velocity = movement * speed;
gameControllerScript = gameControllerObj.GetComponent<GameController>();
if(!gameControllerScript.restart)
{
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
Vector3 movementDelta;
movementDelta = new Vector3(touchDeltaPosition.normalized.x, touchDeltaPosition.normalized.y, 0);
rigidbody.velocity = movementDelta * speed;
//transform.Translate(touchDeltaPosition.x/30, touchDeltaPosition.y/30, 0);
//Debug.Log ("you jus DRAG dem one");
}
rigidbody.position = new Vector3
(
Mathf.Clamp (rigidbody.position.x, boundary.xMin, boundary.xMax),
Mathf.Clamp (rigidbody.position.y, boundary.yMin, boundary.yMax),
0.0f
);
}
if(gameControllerScript.restart)
{
Debug.Log("Restart TRUE");
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
{
transform.position = gameControllerScript.playerSpawn;
gameControllerScript.restart = false;
gameControllerScript.spawnMultiplier = 0;
}
}
rigidbody.rotation = Quaternion.Euler (rigidbody.velocity.y * tilt , rigidbody.velocity.x * -tilt, 0.0f);
}
Comment
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Increase difficulty Space Shooter 2 Answers
How to move 2d object with touch anyscreen point 0 Answers
Rotate with two fingers 0 Answers