- Home /
What would be the best method by which to recreate the horizontal "swipe" mechanic of the game "Splashy!"?
I am attempting to recreate the mechanic that allows you to swipe the sphere left and right from the game "Splashy!".
Here is a link to its gameplay: https://www.youtube.com/watch?v=uuzjX-3Lu5o
Specifically, I'm interested in its fluid and responsive motion when swiping.
Thank you.
Answer by cybersparrow · Jul 03, 2020 at 09:43 AM
@jamiecorkhill5 Still looking for some helpful information... any idea? Did you figured it out lol? :/
Answer by ReneSchleese · Jul 03, 2020 at 09:42 AM
You are looking for something like this, pseudo-code:
void Update()
{
if(TheUserIsSwiping)
{
Vector3 newPosition = ProjectTouchToWorldPosition();
sphere.transform.position = newPosition;
}
}
Vector3 ProjectTouchToWorldPosition()
{
Vector2 touchPosition = Input.GetTouch(0).position;
// Just an example. What you return here heavily depends on your setup and game design
return Vector3.one * touchPosition.x;
}
Basically you want to implement a relation between the finger position on your screen, and the player position in the 3d world. Unity's Input class provides lots of information about the current touches on screen.
Regarding the "fluid and responsive motion": this is where game designers and programmers spend most of their time polishing the mechanic and try to get it to "feel good". When setting the position directly like above in the pseudo-code, you already get maximum responsiveness. To make the motion more fluid you could use smoothing operations on the position, like Vector3.Lerp() or Vector3.SmoothDamp()
Your answer
![](https://koobas.hobune.stream/wayback/20220612165420im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to display Swipe Marks on iPhone 1 Answer
Camera momentum after lifting finger 0 Answers
Detect the swipe and add force respective to it? 3 Answers
Custom touch phase? 0 Answers
Unity2D iOS Dragable items by touch 0 Answers