- Home /
Shooting AI problem
I have two cubes that can fly around and shoot at eachother and avoid obstacles and all that but one of the cubes for some reason its bullets shoot itself. I think it's instantiating inside the cube but i'm not sure. how can i fix this? Could I possibly just move the instantiate point outside the cube? Heres the part of the script where it instantiates:
if (distance < attackThreshold && Time.time - lastShot > shotRepeatTime ) {
var instantiatedProjectile : Rigidbody = Instantiate(shot, myTransform.position, myTransform.rotation);
instantiatedProjectile.velocity = transform.TransformDirection(Vector3(0, 0, shotSpeed));
audio.Play();
}
all the variables work fine and all just can't get one of the cubes to stop shooting itself. Also the other cube has the same script but it doesn't shoot itself and they are identical. Still can't figure that out though. Thanks!
Answer by AngryOldMan · Apr 30, 2011 at 01:57 PM
is it because this one defiant cube is slightly bigger in scale than the rest? any how to get it to appear on an offset instead of
var instantiatedProjectile : Rigidbody = Instantiate(shot, myTransform.position, myTransform.rotation);
use
var instantiatedProjectile : Rigidbody = Instantiate(shot, myTransform.position+Vector3.forward*offset, myTransform.rotation);
then stick a variable at the top called var offset : int = 1;
then you can change it in the inspector till it stops shooting itself
they aren't different sizes. thats what i thought at first too. but i just copied the other cube so they should be the same. the offset worked but i wish i could figure out why its shooting itself.
I just figured it out. on the bullet script i forgot to make a seperate check to see if its hitting anything other than the A enemy. so it only does damage to enemyA. the other cube does the same thing but it doesn't detect enemyB.
shouldn't "myTransform.position+Vector3.forward" be "myTransform.position+myTransform.forward"? Otherwise the firing point moves 1 unit in the global Z direction, ins$$anonymous$$d of in the Z direction local to my Transform, correct?
Answer by Bram 1 · Apr 30, 2011 at 01:40 PM
The object where the bullets are instantiating has to be outside the cube's collider. so that if a bullet instantiates it doesn't collide with the cube itself.
i think this is your problem
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
AI Waypoint help or suggestions!? 2 Answers
Can See Target Not Working 1 Answer
ai navigation help 0 Answers