2017-02-14 1 views
-1

私はプレーヤーとトラックを持っています。私はプレーヤーに速度を適用して、道路内を右または左に移動できるようにしました。速度が動作しないためのMathf.Clamp

プレーヤーはリジッドボディ(rb)で、プレーヤーを移動する速度を適用しています。唯一の私は、以下に適用されている道路で左隣のプレイヤーを移動するための

Vector2 clampPos = new Vector2 (-playerSpeed, 0); 
clampPos.x = Mathf.Clamp (clampPos.x, -maxPoistion, maxPoistion); 
rb.velocity = clampPos; 

しかし、プレイヤーは、まだ最大位置の外に移動されます。

答えて

0

速度をクランプする代わりに、位置を固定する必要があります。

rb.velocity = new Vector2 (playerSpeed, 0); 
Vector2 clampPos = rb.position; 
clampPos.x = Mathf.Clamp (clampPos.x, -maxPoistion,maxPoistion); 
rb.position = clampPos; 
関連する問題