Greetings Everyone,
I need help building a missile or rocket that has the potential of hitting a t\arget anywhere on a planet, but the part where hitting the target on the other side of the planet is very difficult
(I have 2 months of coding exp. with c# not much with javascript) This is what i used, but i can’t get the missile to hit the target on the other side without it leaving completely out of view and coming back a lot later
#pragma strict
var missileVelocity : float = 300;
var turn : float = 20;
var homingMissile : Rigidbody;
var fuseDelay : float;
var missileMod : GameObject;
var smokePrefab : ParticleSystem;
var missileClip : AudioClip;
var force : Vector3; //variable for "lift" of the rocket
var relativeTorque : Vector3; //variable for torque (spin) of rocket
var liftSpeed : float; //determines how much force will be applied
var turnSpeed : float; //determines how much torque will be appled
private var target : Transform;
function Start()
{
homingMissile = transform.rigidbody;
Fire();
}
function Fire()
{
yield WaitForSeconds(fuseDelay);
AudioSource.PlayClipAtPoint(missileClip, transform.position);
var distance = Mathf.Infinity;
for (var go : GameObject in GameObject.FindGameObjectsWithTag("target"))
{
var diff = (go.transform.position - transform.position).sqrMagnitude;
if(diff < distance)
{
distance = diff;
target = go.transform;
constantForce.force = Vector3.up * liftSpeed; //determines the "lift"
constantForce.relativeTorque= Vector3(0,turnSpeed,0);
}
}
}
function FixedUpdate()
{
if(target == null || homingMissile == null)
return;
homingMissile.velocity = transform.forward * missileVelocity;
var targetRotation = Quaternion.LookRotation(target.position - transform.position);
homingMissile.MoveRotation(Quaternion.RotateTowards(transform.rotation, targetRotation, turn));
}
function OnCollisionEnter(theCollision : Collision)
{
if(theCollision.gameObject.name == "Cube")
{
smokePrefab.emissionRate = 0.0f;
Destroy(missileMod.gameObject);
yield WaitForSeconds(5);
Destroy(gameObject);
}
}
Please can anyone help me with a solution,
Thank you.
Notes:
now i tried every way possible with the code i have, but i can’t achieve it. (some Ideas) I also tried adding gravity to the planet but it messes the targeting of the rocket, I thought about using a straight plane and adding a shader to curve it into a planet, but I don’t know how. I have used way points but it doesn’t look right, the rocket points else where.