Question by
Ian-McCleary · Sep 16, 2016 at 04:20 PM ·
3dvector3quaternionaiming
How to add height to an aiming system (JS)
I have a simple aim and shoot system for a turret looking at an enemy. Currently, I calculate the position of the enemy and then shoot with the code below. However, I think i did something wrong because my aiming code does not work if the enemy is not level with the turret. As you can see in the screenshots, the turret shoots over or under the enemy if the enemy is not at the same height. Can someone with vector knowledge please help me? I appreciate any comments and you can see code and screenshots below :)
Aiming Code:
function CalculateAimPosition(targetPos : Vector3){
var aimPoint = Vector3(targetPos.x-turretBall.position.x,targetPos.y-turretBall.position.y,targetPos.z-turretBall.position.z);
desiredRotation = Quaternion.LookRotation (aimPoint);
}
alt text
capture.png
(73.5 kB)
capture1.png
(77.6 kB)
Comment