- Home /
Predict Collision
// I would like to make a shooter that can predict target position so that it can always hit the target.
// The target speed (doesnt change) and the bullet speed is known.
float a1 = Vector3.Angle(target.position + target.forward * targetSpeed, transform.position - target.position);
float a = Mathf.Asin(Mathf.Sin(a1 * Mathf.PI / 180f) * targetSpeed / bulletSpeed) * 180f / Mathf.PI;
Vector3 d = target.position - transform.position;
float b = Quaternion.LookRotation(d).eulerAngles.y + a;
Vector3 c = Quaternion.LookRotation(d).eulerAngles + d.normalized * a;
// This worked only on a plane
//transform.eulerAngles = new Vector3(0f, b, 0f);
// I tried to make it work in 3D, but didnt work
//transform.eulerAngles = c;
Comment
Your answer
Follow this Question
Related Questions
I Want To Shoot Bullets Correctly. 2 Answers
Collision not working... [Solved (b/c I'm dumb)] 1 Answer
Navmesh interfering with shooting mechanics 1 Answer
How to destroy bullet upon colliding with another object instead of bouncing off of it 3 Answers
Move the bullet from the BulletEmitter in the direction player is facing 3D. 1 Answer