滚动球纹理平滑统一3D

时间:2018-09-17 17:03:38

标签: unity3d

我想根据玩家输入,默认情况下垂直滚动以及基于玩家手指移动以及一点点水平滚动来平滑滚动球纹理。

最喜欢这种游戏的实现方式: Catch up - Ketchapp

我曾尝试从我这边写一些东西,但未能获得令人满意的结果。

BallHorizo​​ntalInputHandler脚本:

 public class BallInputHandler : MonoBehaviour
{

 private Vector3 lastTouchPos;
 private Vector3 currTouchPos;
 private bool isTouchRunning;

 //
 [HideInInspector]
 public float horizontalInput;

 public float smoothnessValue;

 void Update ()
 {
     if (Input.GetMouseButtonDown (0)) {
         lastTouchPos = Camera.main.ScreenToViewportPoint (Input.mousePosition);
         isTouchRunning = true;
     } else if (Input.GetMouseButtonUp (0)) {
         isTouchRunning = false;
     }

     if (isTouchRunning) {
         currTouchPos = Camera.main.ScreenToViewportPoint (Input.mousePosition);
         horizontalInput = (currTouchPos.x - lastTouchPos.x) * smoothnessValue;
         //            horzGestureDiff = horzGestureDiff > 0.5f ? 0.5f : horzGestureDiff;
         lastTouchPos = currTouchPos;
     } else
         horizontalInput = 0f;
 }
}

BallController脚本:

 void Update ()
 {
     if (!GameManager.Instance.IsGameRunninng)
         return;

     // ball texture rolling
     textureOffset.x -= myRigidBody.velocity.normalized.z * (speed / 500f);
     textureOffset.y = myRigidBody.velocity.normalized.x * (speed / 30f);
     myMaterial.mainTextureOffset = Vector2.Lerp (myMaterial.GetTextureOffset ("_MainTex"), textureOffset, speed * Time.deltaTime);
}

根据球的当前速度,我更新了球的速度。

现在给我一些有用的建议,以便我可以实施并正确滚动。

0 个答案:

没有答案