【发布时间】:2018-07-27 10:38:20
【问题描述】:
我一直致力于学习部分的滚球项目。我最近添加了一个“速度”文本字段,我注意到当我第一次开始播放时,如果按 W 或 S,那么速度不会超过 3.8(或低于 -3.8)。如果我只向左或向右移动一根头发,这将解决问题,我可以像往常一样使用 W 和 S 移动。如果我将球撞到墙上,也会发生同样的问题。如果我在编辑器中从 (.0000001, .5, 0) 而不是 (0, .5, 0) 开始球,也不会发生故障。以防万一我把代码搞砸了,我会把它贴在下面。
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float moveSpeed;
public float accelSpeed;
private int pickupCount;
public Text countText;
public Text winText;
public Text speedGage;
void Start(){
pickupCount = 0;
setCountText();
winText.text = "";
speedGage.text = "0";
}
void FixedUpdate(){
updateMovement();
}
void updateMovement(){
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(moveHorizontal,0,moveVertical);
rigidbody.AddForce(movement * moveSpeed * Time.deltaTime);
speedGage.text = rigidbody.velocity.ToString();
}
void OnTriggerEnter(Collider other){
if(other.gameObject.tag == "PickUp"){
other.gameObject.SetActive(false);
pickupCount += 1;
setCountText();
}
}
void setCountText(){
countText.text = "Count: " + pickupCount.ToString();
if(pickupCount == 16){
winText.text = "You Win!";
}
}
}
【问题讨论】:
标签: unity3d game-physics