31 lines
935 B
C#
31 lines
935 B
C#
using RayFire;
|
|
using UnityEngine;
|
|
|
|
public class Missle : MonoBehaviour
|
|
{
|
|
|
|
public Transform targetTrans;
|
|
public float moveSpeed = 10;
|
|
public float rotateSpeed = 5;
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
if (targetTrans == null)
|
|
return;
|
|
var dir = targetTrans.position - this.transform.position;
|
|
var targetRot = Quaternion.LookRotation(dir, Vector3.up);
|
|
this.transform.rotation = Quaternion.Slerp(this.transform.rotation, targetRot, Time.fixedDeltaTime * rotateSpeed);
|
|
this.transform.position += this.transform.forward * moveSpeed * Time.fixedDeltaTime;
|
|
}
|
|
|
|
private void OnCollisionEnter(Collision collision)
|
|
{
|
|
if (collision.transform == targetTrans)
|
|
{
|
|
targetTrans.GetComponent<RayfireRigid>().physics.velocity =
|
|
(targetTrans.position - this.transform.position).normalized
|
|
* 100.0f;
|
|
}
|
|
}
|
|
}
|