我想创建球目标预览路径与触摸输入,我尝试了它,并创建了只有一个方向,但我想创建与3型弧。
目标和原点位置固定,但改变弧线路径取决于控制
-
如果用户向右滑动,则使用圆弧绘制路径原点到目标,使用右侧x=10绘制圆弧曲线
-
如果用户向左滑动,则用圆弧绘制路径原点到目标,用左侧的圆弧曲线x=-10
-
如果用户位于中心,则绘制路径原点到目标,并绘制圆弧曲线,X=0
void Update()
{
if (Application.isMobilePlatform)
{
// If pressed with one finger
if (Input.GetMouseButtonDown(0))
{
pressX = Input.touches[0].position.x;
pressY = Input.touches[0].position.y;
}
else if (Input.GetMouseButtonUp(0))
{
pressX = 0;
pressY = 0;
}
if (pressX != 0)
{
float currentX = Input.touches[0].position.x;
if (currentX < pressX)
XValue = (currentX - pressX) / 100;
else if (currentX > pressX)
XValue = (currentX - pressX) / 100;
if (target.transform.position.y < 45.0f)
{
TargetPosition = target.transform.position;
print("YValue : " + YValue);
TargetPosition.x += XValue;
TargetPosition.y += YValue;
target.transform.position = TargetPosition;
}
else
{
TargetPosition = target.transform.position;
print("YValue : " + YValue);
TargetPosition.x += XValue;
TargetPosition.y += YValue;
if (target.transform.position.y > 45.0f)
TargetPosition.y = 45;
target.transform.position = TargetPosition;
}
DrawPath();
}
if (pressY != 0)
{
float currentY = Input.mousePosition.y;
if (currentY < pressY)
YValue = (currentY - pressY) / 100;
else if (currentY > pressY)
YValue = (currentY - pressY) / 100;
if (target.transform.position.y < 45.0f)
{
TargetPosition = target.transform.position;
print("YValue : " + YValue);
TargetPosition.x += XValue;
TargetPosition.y += YValue;
target.transform.position = TargetPosition;
}
else
{
TargetPosition = target.transform.position;
print("YValue : " + YValue);
TargetPosition.x += XValue;
TargetPosition.y += YValue;
if (target.transform.position.y > 45.0f)
TargetPosition.y = 45;
target.transform.position = TargetPosition;
}
DrawPath();
}
}
else
{
if (Input.GetMouseButtonDown(0))
{
pressX = Input.mousePosition.x;
pressY = Input.mousePosition.y;
}
else if (Input.GetMouseButtonUp(0))
pressX = 0;
if (pressX != 0)
{
float currentX = Input.mousePosition.x;
float currentY = Input.mousePosition.y;
if (currentX < pressX)
XValue = (currentX - pressX) / 100;
else if (currentX > pressX)
XValue = (currentX - pressX) / 100;
if (currentY < pressY)
YValue = (currentY - pressY) / 100;
else if (currentY > pressY)
YValue = (currentY - pressY) / 100;
if (target.transform.position.y < 45.0f )
{
TargetPosition = target.transform.position;
print("YValue : " + YValue);
TargetPosition.x += XValue;
TargetPosition.y += YValue;
target.transform.position = TargetPosition;
//target.transform.position = new Vector3(target.transform.position.x, target.transform.position.y + YValue, target.transform.position.z);
}
else
{
TargetPosition = target.transform.position;
print("YValue : " + YValue);
TargetPosition.x += XValue;
TargetPosition.y += YValue;
if (target.transform.position.y > 45.0f)
TargetPosition.y = 45;
target.transform.position = TargetPosition;
}
DrawPath();
}
else
{
}
}
if (Input.GetMouseButtonUp(0))
{
print("Mouse Click Call");
//Rigidbody obj = Instantiate(ball, transform.position, Quaternion.identity);
//obj.velocity = Vo;
ball.position = transform.position;
Physics.gravity = Vector3.up * gravity;
ball.useGravity = true;
ball.velocity = CalculateLaunchData().initialVelocity;
}
}
我创造了如下:
我想要像:
Reference Video