- Home /
projectile speed and Direction different in some devices
Hi, I am working on a 3d Paper toss game. The game works fine on my android and some other devices.. but i tested it on Samsung galaxy tablet and a Samsung phone. the paper(Projectile was too fast) and the swipe direction is way off. - so the question how can i make the script below behaves the same on all Android devices Thank you
void Update()
{
if (shootEnable && Gotothrow)
{
if (Input.touchCount > 0)
{
var touch = Input.touches[0];
switch (touch.phase)
{
case TouchPhase.Began:
touchStart = touch.position;
break;
case TouchPhase.Moved:
if (Mathf.Abs(touch.position.x - touchStart.x) < comfortZone)
{
couldBeSwipe = false;
}
else
{
couldBeSwipe = true;
}
break;
case TouchPhase.Stationary:
if (Mathf.Abs(touch.position.x - touchStart.x) < comfortZone)
{
couldBeSwipe = false;
}
break;
case TouchPhase.Ended:
float swipeDist = (touch.position - touchStart).magnitude;
swipeDist= swipeDist /2.0f;
//couldBeSwipe
if (couldBeSwipe || swipeDist > comfortZone)
{
GetVelocity = false;
touchEnd = touch.position;
GameObject ball = Instantiate(ballPrefab, basetothrow.position, Quaternion.identity) as GameObject;
GetAngle();
ball.GetComponent<Rigidbody>().velocity=(new Vector3((worldAngle.x/-2), (swipeDist * Time.fixedDeltaTime), (swipeDist * 3 * Time.fixedDeltaTime)));
}
break;
default:
break;
}//end switch case
}
}
}
void GetAngle()
{
worldAngle = this.GetComponent<Camera>().ScreenToWorldPoint(new Vector3(touchEnd.x, touchEnd.y + 50f, ((this.GetComponent<Camera>().nearClipPlane - 73.0f))));
}
if you have an android : you can see the issue by downloading it... iyt is not a complet game yet i put it up for QA purposes.. thanks again https://play.google.com/store/apps/details?id=com.abgames.paperfuss
$$anonymous$$aybe it's because you are using Time.fixedDeltaTime ins$$anonymous$$d of Time.DeltaTime, and the fixedDeltaTime is making it go faster because the other device has a significantly faster processor and therefore has a smaller fixedDeltaTime.
Answer by RetroZelda · Dec 07, 2016 at 12:55 PM
could be since Touch.position is in pixel coordinates, the the higher the screen's resolution is, the more pixels will be traveled when swiping. You could try scaling the swipe distance to accommodate different resolutions.
Thank you for your reply.. what do you mean exactly. 1-divide swipe distance by some number 2-use width and height of the screen to generate a number and divide the swipe distance please explain..also if you can add short line of code or example that will be great
Your answer
Follow this Question
Related Questions
Falling Character needs its position reset after swipe 1 Answer
Flick object using up swipe iOS/Android 2 Answers
Swipe control for circle (Can do swipe left/right) 2 Answers
.NET System ticks on Android - what am I doing wrong? 0 Answers
please please please very urgent, can someone convert this script for android swipe 0 Answers