- Home /
Enemy needs to shoot precisely at player
I'm using the FPS Tutorial and now i have a problem with it. The enemy didn't shoot precisely. One of the 10 bullet hits me, also if i stand at one place, it can't hit me. Is there someone can help this and tell me how to fix it. Because the mention of the enemy is that he is killing you, but if one of his bullets is hit me, it has no function.
Please help, IT'S A SERIOUS PROBLEM...
I think something you can do(if you don't) is to put a force in the bullet and make the rigid-body in kinematic so it doesn't moves
@Uriel: You are not making much sense. $$anonymous$$ake the bullet kinematic so it doesn't move, and then apply force (that still doesn't move it)?
Thnx for the reaction, but i forgot to tell you that i'm new in unity and i'm discovering a little. So can you tell me in detail maybe how to do?
I am saying to add a rigidbody(Component>Physics>rigidbody)and make it kinematic and then put a constant force (Component>Physics>constant force) and then put a force so the bullet goes forward so it doesn't goes up or down
Answer by Weitzel · Mar 24, 2011 at 10:50 PM
I just took a look at the tutorial you are talking about.
In this project, on the Robot prefab, there is a script called AI.js;
The problem lies between two things
var shoot angle = 4.0
This poses an issue. With this too small, it will shoot less often, and be much less likely to hit you if you are moving. It won't "lead" a shot.
With this too large, if it doesn't continue to turn, you will be satisfied without actually being pointed at the target.
The other thing is really the heart of the issue. If you notice, he always shoots just to your left. His rockets shoot from his right.
The rotation it is being satisfied from is his gameObject.transform to yours, when instead it needs to be from his child (rocket launcher).transform to yours. This is why it thinks it is aiming at you when it isn't.
Answer by efge · Mar 24, 2011 at 10:37 PM
I do not know the FPS Tutorial, but you could use this script. Assign the tag "Player" to your player object and attach this script to your bullet prefab. (The smooth value defines the duration of the "flight".)
var target : Transform; var smooth : float = 5.0;
function Start () { target = GameObject.FindWithTag("Player").transform; }
function Update () { transform.position = Vector3.Lerp (transform.position, target.position,Time.deltaTime * smooth); }
Your answer
Follow this Question
Related Questions
How to reach multiple GameObjects' value , enemy AI 1 Answer
make Enemy shoot at player 2 Answers
Enemys following and shooting 1 Answer
How to stop enemies from shooting each other 1 Answer
Make enemy more intelligent 0 Answers