好吧我正在做一个自上而下的射击游戏我用screentoworld视图让我的角色看着鼠标,我让我的相机跟随我的玩家x和z轴,但任何时候我的角色从鼠标平行移动它开始摇动我认为它是因为它看着鼠标鼠标的真实世界位置取决于相机的位置,但我不确定。
这里是玩家脚本,许多反斜杠显示了我尝试过的其他事情
gameObject.GetComponent<Rigidbody>().velocity = new Vector3(Input.GetAxisRaw("Horizontal")*movementspeed,0,Input.GetAxisRaw("Vertical")*movementspeed);
if (gameObject.GetComponent<Rigidbody> ().velocity.x != 0 && gameObject.GetComponent<Rigidbody> ().velocity.z != 0) {
gameObject.GetComponent<Rigidbody>().velocity = new Vector3(Input.GetAxisRaw("Horizontal")*movementspeeddiag ,0,Input.GetAxisRaw("Vertical")*movementspeeddiag);
}
// makes vector 3 type target equall to mouse position on pixial cordinates converted in to real world coordniates
target = camera.ScreenToWorldPoint (new Vector3(Input.mousePosition.x,Input.mousePosition.y,camera.transform.position.y - transform.position.y));
//Vector3 newtarget = target - transform.position;
//lerptarget = Vector3.Lerp (transform.eulerAngles,newtarget, 100);
// states the vector 3 values of target
// makes object local z face target and iniziates up axis
//Quaternion rotation = Quaternion.LookRotation (newtarget, Vector3.up);
//transform.eulerAngles = Vector3.up * Mathf.MoveTowardsAngle (transform.eulerAngles.y, rotation.eulerAngles.y, rotatespeed * Time.deltaTime);
transform.LookAt (target,Vector3.up);
和相机脚本
void LateUpdate(){
position = new Vector3 (player.transform.position.x, 10, player.transform.position.z);
transform.position = position;
//transform.localPosition = Vector3.Lerp (transform.position, position, speed *Time.deltaTime);
transform.eulerAngles = new Vector3 (90,0,0);
}
答案 0 :(得分:0)
问题可能是你改变了刚体的速度。应用每个固定更新时间间隔的速度变化,它与帧更新时间不匹配,并可能导致抖动。根据统一文档,你应该尽量避免直接改变速度。 (http://docs.unity3d.com/ScriptReference/Rigidbody-velocity.html)
我建议你使用MovePosition和Lerp功能来实现玩家移动。 看到这个: http://docs.unity3d.com/ScriptReference/Rigidbody.MovePosition.html http://docs.unity3d.com/ScriptReference/Vector3.Lerp.html