敌人跟随玩家,轮换

时间:2015-04-24 14:36:16

标签: c# unity3d model rotation blender


我创建了跟随玩家并旋转的敌人。我的问题是我的宇宙飞船模型旋转不同于我用Blender制作它时 这就是Enemy如何跟随旋转X:0 Y:0 Z:0的船的样子 http://i.stack.imgur.com/bLbaz.png
在搅拌机中,一切都很好,旋转等没有问题 这是敌人脚本

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);

1 个答案:

答案 0 :(得分:0)