- Home /
Cross Platform Input touchpad acceleration
So I downloaded the cross platform input manager and i have the touchpad script on an image in the ui canvas. I have it on swipe because its probably the best way to aim in mobile fps games. However, it is not easy to aim, because it is too sensitive to aim, but far too slow to do things like make a 180 degree turn. So let's take an example like Minecraft Pocket Edition which has very good mobile fps controls. I noticed that it has acceleration so you can aim at small things while having the ability to do a 180 degree turn if you move it across the screen pretty fast. How do i apply this to Touch Pad script in cross platform input, so that you can do pinpoint aiming, while still having the ability to turn around?
Answer by MusapKahraman · Feb 12, 2017 at 09:07 AM
This would solve your problem. Attach the script on a camera.
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;
public class Controller : MonoBehaviour
{
float controlSpeed;
public float sensitivity = 15;
public int maxSpeed = 250;
void Update()
{
if (Input.touchSupported)
{
controlSpeed = Input.GetTouch(0).deltaPosition.magnitude * sensitivity;
controlSpeed = controlSpeed > maxSpeed ? maxSpeed : controlSpeed;
}
else
controlSpeed = 3 * sensitivity;
controlSpeed = controlSpeed * Time.deltaTime;
transform.Rotate(-controlSpeed * CrossPlatformInputManager.GetAxis("Vertical"), controlSpeed * CrossPlatformInputManager.GetAxis("Horizontal"), 0);
}
}