- Home /
Question by
PattyQubed · Mar 24, 2017 at 10:35 PM ·
input3dmobilemobile devices
Touch input position determining player movement speed.
Hi, I'm working on a 3D platforming game for mobile devices and I have reached a point where I can't quite get the movement speed to work the way I want. What I have currently is this very binary movement function where the player is either moving or not moving based on their initial touch position.
public void MoveForward () {
//the intial touch pos
float mY = Input.mousePosition.y;
Vector2 tY;
if (Application.isMobilePlatform) {
tY = Input.GetTouch (0).position;
} else {
tY = new Vector2 (0f, 0f);
}
// for joystick like movement. the if statement creates an effect similar to a deadzone on a game pad
if (mY > verticalMove + Screen.height / deadZone || tY.y > verticalMove + Screen.height / deadZone) {
//the player can only ever move forward in to the screen
moveDirection = Vector3.forward;
moveDirection = transform.TransformDirection (moveDirection);
moveDirection *= speed;
} else if (mY < verticalMove + Screen.height / deadZone || tY.y < verticalMove + Screen.height / deadZone) {
StopMoving ();
}
jumpCount = 0;
}
I don't think this is the most amazing code, but I'm a designer so I try to make code that achieves the desired effect, this almost get me there but I'm out of ideas to change the speed based on the touch different from the initial touch position.
Any suggestions for implementing something like this would be appreciated greatly.
Thanks! :)
Comment