Question by
UnityCSharpNoob · Feb 19, 2017 at 04:15 PM ·
aiprojectileaim
instantiate projectiles towards player
Hi!
Ive made a enemy AI that fires once the player is in range how ever I have problems with the aim of the AI.
It instantiates the object correctly when it comes to the bullet projectile moving forward how ever if I am on a hill and the enemy is slightly below me it just constantly fires in a strait line, not moving the aim.
GameObject Temporary_Bullet_Handler;
Temporary_Bullet_Handler = Instantiate(Bullet, Bullet_Emitter.transform.position, Bullet_Emitter.transform.rotation) as GameObject;
Temporary_Bullet_Handler.transform.Rotate(Vector3.left * 90);
Rigidbody Temporary_RigidBody;
Temporary_RigidBody = Temporary_Bullet_Handler.GetComponent<Rigidbody>();
Temporary_RigidBody.AddForce(transform.forward * BulletForwardForce);
Destroy(Temporary_Bullet_Handler, 10.0f);
Here is the script for the spawner of the prefab:
void Update () {
transform.LookAt(myTarget);
Vector3 targetDir = myTarget.position - transform.position;
float step = speed * Time.deltaTime;
Vector3 newDir = Vector3.RotateTowards(transform.forward, targetDir, step, 0.0F);
Debug.DrawRay(transform.position, newDir, Color.red);
transform.rotation = Quaternion.LookRotation(newDir);
}
Comment
Your answer
Follow this Question
Related Questions
Rotation Transformation From Hell 0 Answers
Target lead (aim ahead) problem 1 Answer
NPC move and find 0 Answers
How do I fire a laser at the player's Y level. 0 Answers
Implement Vector3.MoveTowards follow with random movement 0 Answers