敌人跟随玩家,旋转
Enemy follow player, rotation
我创建了跟随玩家并旋转的敌人。我的问题是我的宇宙飞船模型旋转与我用 Blender 制作时不同。
这就是敌人的跟随方式以及轮船的旋转方式 X:0 Y:0 Z: 0
http://i.stack.imgur.com/bLbaz.png
在 Blender 中,一切都很好,旋转等没有问题
这是敌人脚本
using UnityEngine;
using System.Collections;
public class Enemy : MonoBehaviour {
public static float health;
private float reloadTime;
public Rigidbody laser;
public GameObject explo;
public Transform playerShip;
// Use this for initialization
void Start () {
health = 20.0f;
reloadTime = 0.3f;
}
// Update is called once per frame
void Update () {
//transform.LookAt(playerShip.transform.position);
Quaternion rotation = Quaternion.LookRotation(playerShip.transform.position - this.transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 2);
transform.Translate(Vector3.forward * 2 * Time.deltaTime);
reloadTime -= Time.deltaTime;
if(reloadTime <= 0f)
{
Rigidbody clone = Instantiate(laser, transform.position, transform.rotation) as Rigidbody;
clone.velocity = transform.TransformDirection(0, 0, 80);
Destroy(clone.gameObject, 3);
reloadTime = 0.3f;
}
if(health <= 0f)
{
GameObject exp = Instantiate(explo, transform.position, transform.rotation) as GameObject;
Destroy(this.gameObject);
Destroy(exp.gameObject, 1.5f);
}
}
}
这种旋转有什么问题?
如何更改此代码中的旋转以使 X 始终为 270?
Quaternion rotation = Quaternion.LookRotation(playerShip.transform.position - this.transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 2);
我创建了跟随玩家并旋转的敌人。我的问题是我的宇宙飞船模型旋转与我用 Blender 制作时不同。
这就是敌人的跟随方式以及轮船的旋转方式 X:0 Y:0 Z: 0
http://i.stack.imgur.com/bLbaz.png
在 Blender 中,一切都很好,旋转等没有问题
这是敌人脚本
using UnityEngine;
using System.Collections;
public class Enemy : MonoBehaviour {
public static float health;
private float reloadTime;
public Rigidbody laser;
public GameObject explo;
public Transform playerShip;
// Use this for initialization
void Start () {
health = 20.0f;
reloadTime = 0.3f;
}
// Update is called once per frame
void Update () {
//transform.LookAt(playerShip.transform.position);
Quaternion rotation = Quaternion.LookRotation(playerShip.transform.position - this.transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 2);
transform.Translate(Vector3.forward * 2 * Time.deltaTime);
reloadTime -= Time.deltaTime;
if(reloadTime <= 0f)
{
Rigidbody clone = Instantiate(laser, transform.position, transform.rotation) as Rigidbody;
clone.velocity = transform.TransformDirection(0, 0, 80);
Destroy(clone.gameObject, 3);
reloadTime = 0.3f;
}
if(health <= 0f)
{
GameObject exp = Instantiate(explo, transform.position, transform.rotation) as GameObject;
Destroy(this.gameObject);
Destroy(exp.gameObject, 1.5f);
}
}
}
这种旋转有什么问题?
如何更改此代码中的旋转以使 X 始终为 270?
Quaternion rotation = Quaternion.LookRotation(playerShip.transform.position - this.transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * 2);