Smooth Object Drag with Touch

Hello!

I think about how to solve this problem best ( for android ).

My scene is as following:

I want to drag a GameObject called “Dragger” from the left side to the right side of the screen. On this “Dragger” is an flat cube attached via character joint attached - to swing like a tennis- or baseballracket when i drag the “Dragger”. Both are Rigidbodys, DragRigidBody Script attached to the camera.

I want to drag this as fast as possible form left to right to hit a ball in the center of the scene.

Now i have one big problem:

  • I tweak mass and drag values of the racket + dragger to stop the dragger within the screen after release it.but this isn’t satisfying - because when i release the dragger to soon, it will end somewhere in the middle of the screen - release it later it shoots out of the screen. I built a collieder fram around my scene to avoid the “shootout” but now its bouncing back into the screen - not very satisfying either.

I tried a few codes i found in this forum, the smooth follow script of unity - but nothing seems to work well in my scene ( i’m not the biggest coder :roll_eyes: )

What i’m trying to figure out is, how to ease out the movement of the dragged object to the left or right side of the screen, no matter where the dragger was released.

And after all this i have one big questionmark left:

  • I want to drag the racket as fast as possible form one side to the other, to hit the ball. What would be a good starting point, to measure the strenght / speed the ball was hit?

Would be happy about any tip - because i’m not the greatest coder, and i find myself at the moment in jungle of codes :frowning:

For your first problem,
I imagine you drag via Update()
If so, you can set a var boolean that if true, prevents you from dragging essentially breaking the chain.

That var can be set once you hit the ball. I would imagine that that would halt the object. If you add drag, i do not understand…
Justba thought but perhaps Draggger should not be a rigidbody. Since the bat is slave to dragger and draggger does not use real world physics this may help.

Also, to ease it, drag should work.

:.i

To measure the strength…
Speed = distance / time.
So, at beginning of drag start timer.
At contact with ball. Stop timer, calculate speed, use as a factor to add power to ball hit.

Hi thank you for answering - first of all, sorry for my english.
But how will i drag the object without the DragRigidBody Script - that the only way in know, yet.

Oh.
If you are relying on pre written scripts, doing anything will be difficult.

But it is fairly easy. Just set an update() call, to monitor touch number and f touch == 1, or whatever number you want up tp 5 I beleive. But whatever you want for drag. So 1 will do…

function Update()
{
    if (Input.touchCount == 1) 
    {
	if(Input.GetTouch(0).phase == TouchPhase.Moved)   
	{ 
             objectYouWantToMove.transform.position = Input.GetTouch(0).position;
        }
    }
}

thats it!