I have this code to aim at the target
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TrackickSystem : MonoBehaviour
{
public float speed = 3.0f;
public GameObject m_target = null;
Vector3 m_lastKnownPosition = Vector3.zero;
Quaternion m_lookAtRotation;
// Update is called once per frame
void Update()
{
if (m_target)
{
if (m_lastKnownPosition != m_target.transform.position)
{
m_lastKnownPosition = m_target.transform.position;
m_lookAtRotation = Quaternion.LookRotation(m_lastKnownPosition - transform.position);
}
if (transform.rotation != m_lookAtRotation)
{
transform.rotation = Quaternion.RotateTowards(transform.rotation, m_lookAtRotation, speed * Time.deltaTime);
}
}
}
bool SetTarget(GameObject target)
{
if (!target)
{
return false;
}
m_target = target;
return true;
}
}
And this code to shoot at the target
IEnumerator Fire()
{
//instantiate the bullet as gameobject
GameObject Bullet = Instantiate(Bullets, Gun.gameObject.transform.position, Gun.gameObject.transform.rotation* Quaternion.Euler (0f, 0f, 0f)) as GameObject;
Rigidbody RigidBodyBullet = Bullet.GetComponent<Rigidbody>();
RigidBodyBullet.AddForce(RigidBodyBullet.transform.forward * 5);
aslan.Play();// fire sound
//wait until the time between shots to complete and fire again.
IsShoot = false;
Destroy(Bullet, BulletLifeTime);
yield return new WaitForSeconds(TimeBtwShots);
IsShoot = true;
}
It does shoot at the target but the arrow that the turret shoots looks in the wrong rotation. I need to turn it -90 degrees in X rotation. Please help how to do it.