- Home /
Throw a ball in target bucket with swipe but with one drop Unity3D
I am new to Unity3D.
I am working on a game in which i need to throw a ball to target bucket but that won't be a direct drop in a bucket, i need one drop in between and then 2nd drop will be in bucket ( like bowling ).
My camera is set as ball and target bucket will get distance in z axis. I tried different approaches but those will work in either to much of force or direct drop in bucket.
Code :
private float factor = 50.0f;
void OnMouseDown()
{
startTime = Time.time;
startPos = Input.mousePosition;
startPos.z = transform.position.z - Camera.main.transform.position.z;
startPos = Camera.main.ScreenToWorldPoint(startPos);
}
void OnMouseUp()
{
endPos = Input.mousePosition;
endPos.z = transform.position.z - Camera.main.transform.position.z;
endPos = Camera.main.ScreenToWorldPoint(endPos);
force = endPos - startPos;
force.z = force.magnitude;
force /= (Time.time - startTime);
GetComponent<Rigidbody>().AddForce(force * factor);
}
The problem with my code is, it adds too much force in z direction so the drop will be far away after the target bucket and force value for y direction is very low so it won't get in to target bucket.
So i need help to manage y and z axis force depending on swipe in a way so it look realistic.
Thanks for your help in advance.
Answer by fahadshafique · Sep 12, 2018 at 11:30 AM
Did you find any solution to the problem? if you find any then please tell me thanks,Did you find any way to solve this problem? please tell if you find out solution...thanks
Answer by Adishah11 · Sep 20, 2018 at 05:48 AM
Check this asset its has both 2d and 3d implementation with curve control link: https://assetstore.unity.com/packages/tools/physics/2d-and-3d-swipe-ball-control-96912?aid=1100l3bpb
Your answer
Follow this Question
Related Questions
Throw an object via touch/mouse flick 0 Answers
TouchPhase doesn't end when player swipes off screen 1 Answer
mouse input to touch input help please 0 Answers
Swipe menu, problem! 0 Answers
Deactivate Swipe Controls on Pause? 0 Answers