代码之家  ›  专栏  ›  技术社区  ›  Siddharth

在斜坡上以相同速度移动球-Unity 3D

  •  3
  • Siddharth  · 技术社区  · 6 年前

    我想在斜坡上移动球,就像在平地上移动一样。目前当斜坡开始时,球的速度会降低,所以根据玩家的经验,球的整体运动会降低。

    我想保持同样的速度,当它在地面上移动或马虎的地区。

    尽管下面这张图我试图解释我的问题: enter image description here

    void FixedUpdate ()
    {
    
        if (!GameManager.Instance.IsGameRunninng) {
            myRigidBody.velocity = Vector3.zero;
            return;
        }
    
        if (isJumper) {
            isJumper = false;
            myRigidBody.AddForce (Vector3.up * 35f, ForceMode.Impulse);
        }
    
        isGrounded = Physics.Raycast (rayTransform.position, Vector3.down, 0.5f, groundMask);
    
        Vector3 nextVelocity = myRigidBody.velocity;
        nextVelocity.x = ballInputHandler.horizontalInput * smoothnessX;
    
        if (!isGrounded) {
            nextVelocity.y -= speed * 0.3f;
        } else {
            nextVelocity.y = 0;
            nextVelocity.z = speed;
        }
    
        myRigidBody.velocity = Vector3.Lerp (myRigidBody.velocity, nextVelocity, smoothnessValue * Time.fixedDeltaTime);
    
        ClampingBallMovement ();
    
    }
    

    我希望你正确地理解了我的问题,给我一些建议,这样我就可以从这个问题中走出来。

    1 回复  |  直到 6 年前
        1
  •  1
  •   Immersive    6 年前

    在你调整了 nextVelocity.y 组成部分:

        myRigidBody.velocity = nextVelocity.normalized * desiredSpeed;