hi there my friends i have a trouble in making the following:
1-i have a spaceship that is controlled by using (rigidbody.AddRelativeTorque) thats is getting info from the position of the mouse on screen.
2-i have a turret on top of the ship.
3-the turret uses the following script to lead the targets:
#pragma strict
#pragma implicit
#pragma downcast
var damping = 5.0;
var Target : GameObject;
var projSpeed : int;
var fireHitRatio : float;
var targetLead : GameObject;
var enableFire : boolean;
var rotation : Quaternion;
function Start(){
fireHitRatio = 1.15;
}
function Update () {
if (Target != null){
TargetLead();
}else if (Target == null){
NoTargets();
}
}
function TargetLead(){
if (Target != null) {
var TGV = Target.rigidbody.velocity;
projectileSpeed = projSpeed;
var distTarget = Vector3.Distance(Target.transform.position, transform.position);
velocityPosition1 = Target.transform.position + ((TGV * fireHitRatio) * (distTarget/projectileSpeed));
velocityDist1 = Vector3.Distance(velocityPosition1, transform.position);
velocityPosition2 = Target.transform.position + ((TGV * fireHitRatio) * (velocityDist1/projectileSpeed));
velocityDist2 = Vector3.Distance(velocityPosition2, transform.position);
TargetInterceptPosition = Target.transform.position + ((TGV * fireHitRatio) * (velocityDist2/projectileSpeed));
rotation = Quaternion.LookRotation((TargetInterceptPosition) - transform.position);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
}
targetLead.transform.position = camera.main.WorldToViewportPoint(TargetInterceptPosition);
}
function NoTargets(){
targetLead.transform.position = Vector3(0,0,0);
transform.rotation = Quaternion.Slerp(transform.rotation, transform.parent.rotation, Time.deltaTime * damping / 5);
}
4-the turret must be alinged with the ship at all times , but must also try to look at the target lead with the following:
the above script works the best if used on a turret made with 1 piece of geometry.
the turret is made up with 2 parts ,(turret) which moves only on Y Axis , (barrel) which moves only on X Axis but also follows the turret Y Axis.
the troubles i am having:
1-used many scripts , cant list them here but it always mess the rotation of the turret by a really weird rotations.
2-the following script is the best but it does not aim well , it aims little higher than it must be:
var rotationInfo : ProcessingTargets;
var displayedInfo : Quaternion;
function Update (){
displayedInfo = Quaternion.Slerp(transform.rotation, rotationInfo.rotation, Time.deltaTime * rotationInfo.damping);
if (rotationInfo.Target != null){
transform.rotation = Quaternion(displayedInfo.x,displayedInfo.y,displayedInfo.z,displayedInfo.w);
Debug.DrawLine(transform.position,rotationInfo.Target.transform.position,Color(1,1,1,1));
}
}
var turretRotationsInfo : TurretTargeter;
var angle = 0.0;
var axis : Vector3;
var isBarrel : boolean;
function Update (){
axis = turretRotationsInfo.displayedInfo.eulerAngles;
if(isBarrel == false){
transform.localEulerAngles.y = axis.y - 90;
}else if(isBarrel == true){
transform.localEulerAngles.y = axis.x + 1.5;
}
}
please i wish someone really helps me with this because it have taken a long time in debugging , trying , scripting …etc
and also i am having lot of troubles with (quaternions) i have read the documents on it but still didnt understand it fully and i think thats why i failed at fixing this.
thx in adv