How can I change the point of an enemy which a turret(ai) shoots.
I have turrets within my tower defence game which automatically find their target and fire projectiles, a bullet for the standard turret, a missile for the missile launcher and a laser for the laser turret. The problem I am having however is that these projectiles are hitting the feet of the enemies due to the fact that it is aiming for the enemies positions and the Y of the enemies is 0.5 so that it is just on top of the floor. How can I make it so that the turrets aim higher and hit the centre of the enemy. Thank you if you can help, as the turrets shooting the feet of the enemy can be a bit visually ugly.
This is the code responsible for the way turrets lock onto targets.
void LockOnTarget()
{
Vector3 dir = target.position - transform.position;
Quaternion lookRotation = Quaternion.LookRotation(dir);
Vector3 rotation = Quaternion.Lerp(partToRotate.rotation, lookRotation, Time.deltaTime * turnSpeed).eulerAngles;
partToRotate.rotation = Quaternion.Euler(0f, rotation.y, 0f);
}
Answer by saml_baker · Mar 04, 2018 at 07:15 AM
Add an offset to the y coord so instead of using "rotation.y" use "(rotation.y) + [offset value]"
Answer by Honorsoft · Mar 04, 2018 at 10:45 AM
I have to look into this myself (it's in the Unity documentation), but you can target the specific transform of ANY part of the mesh or the 'skeleton'. Sami's advice is a good quick fix, but you could also do (pseudo-code):
TARGET = MODEL_WIDTH/2, MODEL_HEIGHT/2, MODEL_DEPTH/2
..to set the target point at the exact center of the target no matter what size it is.
I had to do a similar setup for my 3D space combat game in DevC++, for targeting the different parts of the enemy ships (engines, weapons, shields, etc). Now I am working on that for a superhero MMORPG in Unity.
I don't completely understand what you mean for me to do here, where in the code should I implement this, do I need to replace a certain part of the code? What do I need to replace the different parts of the pseudocode with? Sorry for asking these stupid questions, i'm relatively new to this.
Your answer
Follow this Question
Related Questions
Trouble with a State Machine for Turret 0 Answers
A little doubt about creating a Talking BOT that simulates AI, for iOS system using Unity. 0 Answers
Several NPC with waypoints 1 Answer
Whats wrong with my car auto park AI scripts?,What am I missing from my car auto park code? 0 Answers
I don't know which asset to use for my TD game see below for info. 0 Answers