so i’ve made a touch pad for my iphone game that works essentially just like a directional pad.
the game is running at 60 fps but when i touch the pad it waits a few milliseconds before moving, and when i stop pressing it the vehicle keeps moving for a few more milliseconds before stopping.
my code is as follows
function MainControlLoop(){
while (true){
if(LatchedFinger==-1){
SearchForTouch();
}
else{
TrackFinger();
}
yield;
}
}
function SearchForTouch(){
var touch : Touch;
for (var i = 0; i < Input.touchCount; ++i) {
if (Input.GetTouch(i).phase == TouchPhase.Began) {
touch = Input.GetTouch(i);
if(TouchForGUI(touch)){
LatchedFinger=i;
sendMove(touch);
return;
}
}
}
}
function TrackFinger(){
var touch : Touch;
touch = Input.GetTouch(LatchedFinger);
sendMove(touch);
if(touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled){
LatchedFinger=-1;
}
}
function TouchForGUI(touch : Touch ) : boolean{
if(rect.Contains(touch.position)){
return true;
}
else{
return false;
}
}
function sendMove(touch: Touch){
var horizontalMove:float = (touch.position.x- centre.ct.x)/centre.ct.width ;
var vertMove:float = (touch.position.y- centre.ct.y)/centre.ct.height ;
main.pC.MoveTank(Mathf.Clamp(horizontalMove,-1,1), Mathf.Clamp(vertMove,-1,1));
}
i’ve tried converting it to a update or fixed update but it seemed to respond even worse then. which makes me think the delay is in my code somewhere but i can’t seem to find it