【发布时间】:2016-01-28 17:45:40
【问题描述】:
我正在尝试制作一个玩家只控制球的左右移动的游戏 (like rolling sky)。球应该始终以恒定的速度向前移动。到目前为止我已经尝试了以下但我只能在空中(跳跃)时左右控制球。
非常感谢任何帮助或链接。
float forwardVelocity = 20.0f
void Update ()
{
if (gameConfig.currentGameState == GameConfig.CurrentGameState.LevelInPlay)
{
handleMovement();
handleJumping();
deathDetection ();
}
}
void handleJumping()
{
if ((Input.GetMouseButtonDown(0) || Input.GetButtonDown("Jump")) && isGrounded)
{
rigidBody.velocity = new Vector3(rigidBody.velocity.x, jumpHeight, rigidBody.velocity.z);
jumpSound.Play();
}
}
void handleMovement()
{
var moveHorizontal = Input.GetAxis ("Horizontal");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, 0.0f);
rigidBody.AddForce (movement * rotationSpeed);
if (rigidBody.velocity.z < forwardVelocity)
{
rigidBody.velocity = new Vector3(rigidBody.velocity.x, rigidBody.velocity.y, forwardVelocity);
}
}
【问题讨论】:
-
我认为这是因为你在速度更新之前添加了力量然后覆盖它。
-
好收获。我会尝试移动它们,看看是否有帮助。谢谢
标签: unity3d