- Home /
I need help with my 2D Android character controller
I am trying to create a Script for a 2D character which would require the use of touch screen , What i am trying to get the script to do is take the position x input from the joystick and ive set it so that if the joystick is less that 0 then the character moves left and faces left and if the position x number is more than 0 then face the character right and move the character right.
var moveTouchPad : Joystick;
var jumpTouchPad : Joystick;
var CharacterSprite : Transform;
var forwardSpeed : float = 4;
var backwardSpeed : float = 4;
var facingRight = false;
var flip = 0.7686443;
var anim: Animation;
function Start ()
{
anim = GetComponent.();
if (moveTouchPad.position.x == 0);
animation.Play("Idle");
}
function Update ()
{
if (facingRight == true);
CharacterSprite.localScale.x = transform.localScale.x;
}
{
if (facingRight == false);
CharacterSprite.localScale.x = - transform.localScale.x;
}
{
if (moveTouchPad.position.x > 0 && facingRight == true);
animation.Play("Run");
transform.Translate(Vector3.left * Time.deltaTime);
facingRight = false;
}
{
if (moveTouchPad.position.x < 0 && facingRight == false);
animation.Play("Run");
transform.Translate(Vector3.right * Time.deltaTime);
facingRight = true;
}
Any help would be most apprciated?
Your answer
![](https://koobas.hobune.stream/wayback/20220613185750im_/https://answers.unity.com/themes/thub/images/avi.jpg)