What’s new people?
…Stuck again…
I have a plane with a steer-wheel texture, and is supposed to rotate by y axis when i drag left/right on x axis. But… every time i drag the touchPosition.x, the steer-wheel spins out of control and doesn’t follow my drag so precisely… the best solution would be to limit the rotation of +y and -y and also limit the drag of touchPosition.x (left and right) but i am unable to because of lack of experience…
second thing : the steer-wheel doesn’t stop spinning/rotating when i stop draging or swiping.
I’m trying to get the rotation as smoothly and precisely possible to simulate steering.
How to Fix this?
var RotateTime: float = 0.1;
var SwipeTime: float = 0.4;
var rotateAngle : float = 0.0;
var minAngle;
var maxAngle;
var AnglePos : float = 10;
var AngleNeg : float = -10;
var currentAngle;
var object : Vector3;
function Update() {
//this is the rotate function...-- is there a alternative?
transform.Rotate(0, rotateAngle, 0);
//the Touch Boundary
var Boundry : Rect = Rect(0, 0, 250, 250);
//swipe Function
for (var j=0; j < Input.touchCount; ++j){
var drags : Touch = Input.touches[j];
if(drags.phase == TouchPhase.Began Boundry.Contains(drags.position)){
minAngle = drags.position.x;
Debug.Log("touched" + minAngle);
}
else if(drags.phase == TouchPhase.Moved Boundry.Contains(drags.position)){
maxAngle = drags.position.x;
}
else if(drags.phase == TouchPhase.Ended){
minAngle=maxAngle;
rotateAngle = 0;
}
if(minAngle!=maxAngle){
rotateAngle = (maxAngle - minAngle)/RotateTime;
}
else{
rotateAngle = rotateAngle * SwipeTime;
}
if (rotateAngle >= AnglePos){
rotateAngle = AnglePos;
minAngle=maxAngle;
}
else if (rotateAngle <= AngleNeg){
rotateAngle = AngleNeg;
minAngle=maxAngle;
}
}
}
THX!