Question by
peacetr · Sep 26, 2015 at 09:25 PM ·
controllerballcontrol
how can i make drag and release (like billiard games) ball control
i wanna make drag and release or however it calls ball control system. also i want to do the big drags makes ball go faster. sorry for my bad english :))) pls someone help me about it.. thank you so much
Comment
Answer by Badgerfish · Sep 29, 2015 at 02:21 AM
There's a couple ways of doing this. Here's one.
Make sure your ball has a rigidbody component, you'll need to apply forces to it.
Be ready for a lot of troubleshooting when multiplying the force times the delta.magnitude of mouse distance from original position.
Here's some code in C# to get you started:
Vector3 delta = Vector3.zero;
Vector3 lastPos = Vector3.zero;
void Update()
{
if ( Input.GetMouseButtonDown(0) )
{
lastPos = Input.mousePosition;
}
else if ( Input.GetMouseButton(0) )
{
delta = Input.mousePosition - lastPos;
Debug.Log( "Delta Distance From Starting Position : " + delta.magnitude );
//multiply delta.magnitude times the force you want to apply to the ball and bam! magic!
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612035143im_/https://answers.unity.com/themes/thub/images/avi.jpg)