0
\$\begingroup\$

I have the following C# code, but it leaves me with two problems:

void FixedUpdate()
{
    if (Input.touchCount == 1)
    {
        this.transform.Translate(Input.touches[0].deltaPosition.x * 0.009f, 0, 0); 
    }
}

Firstly, the gameobject (which is a sphere in my case), has a tendency to leave the ground and fly into the air. Additionally, it is not as smooth and snappy but fluid as I would like it to be.

If you look at some of the following gameplay videos, you will see the kind of movement I am looking for.

More specifically, from actually playing each of the above games, there is a certain "ratio" that seems to be operating in regards to each swipe gesture and the actual movement of the ball. That is, the ball does not go exactly where the finger goes, for it is slightly ahead, if that makes sense. What I mean is, the device is only so wide, yet for that width, the ball can always reach it's required destination on either end of the horizontal axis. This must mean that for every pixel the finger moves, the ball moves a little bit more to fit that pixel density of the screen. In other words, in the case of "Splashy!", it's clear that even if the finger moves the entire distance across the screen, the ball moves more than double that distance.

By "smooth", "fluid", and "snappy", I mean that the swiping gesture is very responsive. It moves where you want it to and does not over or undershoot. Additionally, the "snappy" effect is present when you stop swiping. The ball seems to "snap" into it's end position.

My question, then, is what is the best way to improve my script as to achieve the polished mechanic I am looking for, as is depicted in the above videos? Also, how can I keep the sphere on the ground without constraining any axes on the rigidbody? I am using Unity3D with C#.

I would appreciate any help you could provide. Thank you.

\$\endgroup\$
  • \$\begingroup\$ The trouble with "How did X achieve Y" questions is that unless the developer who worked on X's implementation of feature Y sees your question, and isn't bound from answering by an NDA, AND has the wherewithal and time to post an answer, nobody else can answer it for you. Instead, you'll often find you get better answers by rephrasing your question like this: "How can I improve my feature Y? Here's how I've implemented feature Y so far ...[details] and I'm unhappy with [specific symptom 1] and [specific symptom 2] — how can I improve it?" That way anyone who knows a relevant solution can help. \$\endgroup\$ – DMGregory Jun 25 '18 at 19:53
  • \$\begingroup\$ @DMGregory Thank you. What you say makes sense. The problem is, I can build a simple movement script, such as this one: forum.unity.com/threads/… But it does not provide me with the movement I desire. I included the gameplay videos so others could better understand the mechanic I am going for, and possibly provide advice about how to implement it. \$\endgroup\$ – Jamie Corkhill Jun 25 '18 at 20:12
  • \$\begingroup\$ @DMGregory I changed my question. Is that any better? \$\endgroup\$ – Jamie Corkhill Jun 25 '18 at 20:46
  • \$\begingroup\$ Improving! "Smooth" "snappy" "fluid" are words that get thrown around very imprecisely though. This question could be even better if you can explain in words the exact behaviour you want. Try walking through the videos frame-by-frame to identify what makes them tick, so you can describe precisely what you need help creating. This also helps make evaluating the answers more objective: for any given answer, we can check it against the criteria you described and ask "does this proposed solution meet this specific requirement?" rather than fuzzy/subjective evaluations like "is it 'fluid' enough?" \$\endgroup\$ – DMGregory Jun 25 '18 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.