I need help with creating a script that can determine the position of the Crosshair Quad by the sum of the velocities so whenever the player fires at the crosshair the projectiles land on the enemy.Please I need help here is what I have managed so far.Please help me.Thanks in advance
void Update ()
{
//Take rigidbodies so we can take the velocities of target and player.
Rigidbody rigid = transform.root.transform.GetComponent ();
Rigidbody rigidGO = GameObject.FindGameObjectWithTag(โPlayerโ).transform.root.transform.GetComponent ();
//Take transform of player so we can calculate the distance between target
//and player.
Transform GO = GameObject.FindGameObjectWithTag ("Player").transform.root.transform;
//Calculate the distance between player and target.
float dist = Vector3.Distance (transform.root.position, GO.position);
//Bullet travel time?
float bulletTravelTime = dist / (Vector3.forward.magnitude*10f);
//Local position
Vector3 localVel = (bulletTravelTime*(rigid.velocity+rigidGO.velocity));
transform.localPosition = localVel;
}
Further explanation: You can watch videos of a space-sim game called freelancer.The aiming crosshair which helps you hit the enemis is EXACTLY what I want to achieve.
https://www.youtube.com/watch?v=1NFl8Yn7guE At 27:50 the red cross. Cannot be more specific