- Home /
Lock on Enemy Target
I am trying to lock onto a target and shoot while locked.
I have had some sucess with lookAt and using raycast but i can shoot the emeny and the ray works fine but i cant turn away as the lookAt is forcing me back to look at the enemy. i have the lookat on the gun a child of the player.
Thanks
Yes, I would like to lock onto target when mouse down and stay locked until i mouse down again elsewhere.
Answer by BerggreenDK · Nov 29, 2010 at 05:00 AM
how about just encapsulating the Lookat function with something like this:
var isTargeting : boolean;
if (isTargeting) {
// place your current targeting code here
}
then use isTargeting as a flag you set when you turn on targeting.
Answer by Black Widow 1 · Dec 01, 2010 at 10:14 PM
Hi, Thanks for this it works well.
The only this i want to do extra is when i mouseDn on the object the target is locked on by isTargeting and only when i MouseDown elsewhere the is targeting stops.
So really i want to MouseDn on enemy which lock target on and if i Mouse down elsewhere targeting is off.
Im pretty new at all this but really enjoying it.
Thanks
Your answer
Follow this Question
Related Questions
Using Raycast to "Lock On" 1 Answer
Movement while Looking At an enemy 1 Answer
How to implement lock on with a camera that is not a child of the player object? 1 Answer
transform.LookAt not updating each frame until UI Slider input is changed 1 Answer
Making a 2d object lookat a 3d object on the y-axis(c#) 1 Answer